workspace-tools 0.41.0 → 0.41.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.
Files changed (160) hide show
  1. package/README.md +1 -1
  2. package/lib/dependencies/index.d.ts +2 -2
  3. package/lib/dependencies/index.js +31 -12
  4. package/lib/dependencies/index.js.map +1 -1
  5. package/lib/dependencies/transitiveDeps.d.ts +1 -1
  6. package/lib/dependencies/transitiveDeps.js +59 -38
  7. package/lib/dependencies/transitiveDeps.js.map +1 -1
  8. package/lib/getPackageInfo.d.ts +1 -1
  9. package/lib/getPackageInfo.js +46 -40
  10. package/lib/getPackageInfo.js.map +1 -1
  11. package/lib/getPackageInfos.d.ts +4 -2
  12. package/lib/getPackageInfos.js +35 -53
  13. package/lib/getPackageInfos.js.map +1 -1
  14. package/lib/git/config.d.ts +1 -1
  15. package/lib/git/config.js +15 -12
  16. package/lib/git/config.js.map +1 -1
  17. package/lib/git/getDefaultRemote.js +45 -30
  18. package/lib/git/getDefaultRemote.js.map +1 -1
  19. package/lib/git/getDefaultRemoteBranch.d.ts +1 -1
  20. package/lib/git/getDefaultRemoteBranch.js +35 -24
  21. package/lib/git/getDefaultRemoteBranch.js.map +1 -1
  22. package/lib/git/getRepositoryName.d.ts +1 -1
  23. package/lib/git/getRepositoryName.js +17 -19
  24. package/lib/git/getRepositoryName.js.map +1 -1
  25. package/lib/git/git.d.ts +2 -5
  26. package/lib/git/git.js +62 -64
  27. package/lib/git/git.js.map +1 -1
  28. package/lib/git/gitUtilities.d.ts +3 -3
  29. package/lib/git/gitUtilities.js +377 -147
  30. package/lib/git/gitUtilities.js.map +1 -1
  31. package/lib/git/index.d.ts +5 -5
  32. package/lib/git/index.js +50 -28
  33. package/lib/git/index.js.map +1 -1
  34. package/lib/git/types.js +4 -3
  35. package/lib/git/types.js.map +1 -1
  36. package/lib/graph/createDependencyMap.d.ts +2 -2
  37. package/lib/graph/createDependencyMap.js +18 -18
  38. package/lib/graph/createDependencyMap.js.map +1 -1
  39. package/lib/graph/createPackageGraph.d.ts +3 -3
  40. package/lib/graph/createPackageGraph.js +58 -45
  41. package/lib/graph/createPackageGraph.js.map +1 -1
  42. package/lib/graph/getPackageDependencies.d.ts +1 -1
  43. package/lib/graph/getPackageDependencies.js +17 -17
  44. package/lib/graph/getPackageDependencies.js.map +1 -1
  45. package/lib/graph/index.d.ts +4 -4
  46. package/lib/graph/index.js +25 -27
  47. package/lib/graph/index.js.map +1 -1
  48. package/lib/index.d.ts +29 -26
  49. package/lib/index.js +154 -70
  50. package/lib/index.js.map +1 -1
  51. package/lib/isCachingEnabled.js +17 -6
  52. package/lib/isCachingEnabled.js.map +1 -1
  53. package/lib/lockfile/nameAtVersion.js +9 -4
  54. package/lib/lockfile/nameAtVersion.js.map +1 -1
  55. package/lib/lockfile/parseBerryLock.d.ts +1 -1
  56. package/lib/lockfile/parseBerryLock.js +13 -11
  57. package/lib/lockfile/parseBerryLock.js.map +1 -1
  58. package/lib/lockfile/parseLockFile.d.ts +2 -0
  59. package/lib/lockfile/parseLockFile.js +87 -0
  60. package/lib/lockfile/parseLockFile.js.map +1 -0
  61. package/lib/lockfile/parseNpmLock.d.ts +1 -1
  62. package/lib/lockfile/parseNpmLock.js +15 -7
  63. package/lib/lockfile/parseNpmLock.js.map +1 -1
  64. package/lib/lockfile/parsePnpmLock.d.ts +1 -1
  65. package/lib/lockfile/parsePnpmLock.js +14 -9
  66. package/lib/lockfile/parsePnpmLock.js.map +1 -1
  67. package/lib/lockfile/queryLockFile.d.ts +1 -1
  68. package/lib/lockfile/queryLockFile.js +11 -6
  69. package/lib/lockfile/queryLockFile.js.map +1 -1
  70. package/lib/lockfile/readYaml.js +17 -9
  71. package/lib/lockfile/readYaml.js.map +1 -1
  72. package/lib/lockfile/types.js +3 -2
  73. package/lib/lockfile/types.js.map +1 -1
  74. package/lib/logging.js +10 -6
  75. package/lib/logging.js.map +1 -1
  76. package/lib/paths.d.ts +1 -1
  77. package/lib/paths.js +59 -59
  78. package/lib/paths.js.map +1 -1
  79. package/lib/scope.js +30 -21
  80. package/lib/scope.js.map +1 -1
  81. package/lib/types/Catalogs.js +8 -3
  82. package/lib/types/Catalogs.js.map +1 -1
  83. package/lib/types/PackageGraph.js +4 -3
  84. package/lib/types/PackageGraph.js.map +1 -1
  85. package/lib/types/PackageInfo.d.ts +1 -1
  86. package/lib/types/PackageInfo.js +3 -2
  87. package/lib/types/PackageInfo.js.map +1 -1
  88. package/lib/types/WorkspaceInfo.d.ts +1 -1
  89. package/lib/types/WorkspaceInfo.js +3 -2
  90. package/lib/types/WorkspaceInfo.js.map +1 -1
  91. package/lib/types/WorkspaceManager.js +3 -2
  92. package/lib/types/WorkspaceManager.js.map +1 -1
  93. package/lib/workspaces/catalogsToYaml.d.ts +1 -1
  94. package/lib/workspaces/catalogsToYaml.js +12 -10
  95. package/lib/workspaces/catalogsToYaml.js.map +1 -1
  96. package/lib/workspaces/findWorkspacePath.d.ts +2 -1
  97. package/lib/workspaces/findWorkspacePath.js +10 -12
  98. package/lib/workspaces/findWorkspacePath.js.map +1 -1
  99. package/lib/workspaces/getAllPackageJsonFiles.js +32 -28
  100. package/lib/workspaces/getAllPackageJsonFiles.js.map +1 -1
  101. package/lib/workspaces/getCatalogVersion.d.ts +1 -1
  102. package/lib/workspaces/getCatalogVersion.js +19 -32
  103. package/lib/workspaces/getCatalogVersion.js.map +1 -1
  104. package/lib/workspaces/getCatalogs.d.ts +2 -2
  105. package/lib/workspaces/getCatalogs.js +17 -22
  106. package/lib/workspaces/getCatalogs.js.map +1 -1
  107. package/lib/workspaces/getChangedPackages.d.ts +1 -1
  108. package/lib/workspaces/getChangedPackages.js +47 -30
  109. package/lib/workspaces/getChangedPackages.js.map +1 -1
  110. package/lib/workspaces/getPackagesByFiles.js +29 -24
  111. package/lib/workspaces/getPackagesByFiles.js.map +1 -1
  112. package/lib/workspaces/getWorkspaceInfos.d.ts +2 -2
  113. package/lib/workspaces/getWorkspaceInfos.js +43 -58
  114. package/lib/workspaces/getWorkspaceInfos.js.map +1 -1
  115. package/lib/workspaces/getWorkspaceManagerRoot.d.ts +1 -1
  116. package/lib/workspaces/getWorkspaceManagerRoot.js +16 -13
  117. package/lib/workspaces/getWorkspaceManagerRoot.js.map +1 -1
  118. package/lib/workspaces/getWorkspacePackagePaths.d.ts +1 -1
  119. package/lib/workspaces/getWorkspacePackagePaths.js +86 -72
  120. package/lib/workspaces/getWorkspacePackagePaths.js.map +1 -1
  121. package/lib/workspaces/getWorkspacePatterns.d.ts +1 -1
  122. package/lib/workspaces/getWorkspacePatterns.js +18 -20
  123. package/lib/workspaces/getWorkspacePatterns.js.map +1 -1
  124. package/lib/workspaces/implementations/WorkspaceUtilities.d.ts +1 -1
  125. package/lib/workspaces/implementations/WorkspaceUtilities.js +3 -2
  126. package/lib/workspaces/implementations/WorkspaceUtilities.js.map +1 -1
  127. package/lib/workspaces/implementations/getPackageJsonWorkspacePatterns.d.ts +1 -1
  128. package/lib/workspaces/implementations/getPackageJsonWorkspacePatterns.js +24 -22
  129. package/lib/workspaces/implementations/getPackageJsonWorkspacePatterns.js.map +1 -1
  130. package/lib/workspaces/implementations/getWorkspaceManagerAndRoot.d.ts +1 -1
  131. package/lib/workspaces/implementations/getWorkspaceManagerAndRoot.js +38 -43
  132. package/lib/workspaces/implementations/getWorkspaceManagerAndRoot.js.map +1 -1
  133. package/lib/workspaces/implementations/getWorkspaceUtilities.d.ts +2 -2
  134. package/lib/workspaces/implementations/getWorkspaceUtilities.js +25 -13
  135. package/lib/workspaces/implementations/getWorkspaceUtilities.js.map +1 -1
  136. package/lib/workspaces/implementations/index.d.ts +2 -2
  137. package/lib/workspaces/implementations/index.js +19 -7
  138. package/lib/workspaces/implementations/index.js.map +1 -1
  139. package/lib/workspaces/implementations/lerna.d.ts +1 -1
  140. package/lib/workspaces/implementations/lerna.js +55 -31
  141. package/lib/workspaces/implementations/lerna.js.map +1 -1
  142. package/lib/workspaces/implementations/npm.d.ts +1 -1
  143. package/lib/workspaces/implementations/npm.js +12 -7
  144. package/lib/workspaces/implementations/npm.js.map +1 -1
  145. package/lib/workspaces/implementations/pnpm.d.ts +1 -1
  146. package/lib/workspaces/implementations/pnpm.js +28 -17
  147. package/lib/workspaces/implementations/pnpm.js.map +1 -1
  148. package/lib/workspaces/implementations/rush.d.ts +1 -1
  149. package/lib/workspaces/implementations/rush.js +27 -16
  150. package/lib/workspaces/implementations/rush.js.map +1 -1
  151. package/lib/workspaces/implementations/yarn.d.ts +1 -1
  152. package/lib/workspaces/implementations/yarn.js +34 -26
  153. package/lib/workspaces/implementations/yarn.js.map +1 -1
  154. package/lib/workspaces/wrapWorkspaceUtility.d.ts +1 -1
  155. package/lib/workspaces/wrapWorkspaceUtility.js +25 -27
  156. package/lib/workspaces/wrapWorkspaceUtility.js.map +1 -1
  157. package/package.json +21 -12
  158. package/lib/lockfile/index.d.ts +0 -6
  159. package/lib/lockfile/index.js +0 -105
  160. package/lib/lockfile/index.js.map +0 -1
@@ -1,288 +1,518 @@
1
- "use strict";
2
1
  //
3
2
  // Assorted other git utilities
4
3
  // (could be split into separate files later if desired)
5
4
  //
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.listAllTrackedFiles = exports.getDefaultBranch = exports.parseRemoteBranch = exports.getRemoteBranch = exports.getParentBranch = exports.revertLocalChanges = exports.stageAndCommit = exports.commit = exports.stage = exports.init = exports.getFileAddedHash = exports.getCurrentHash = exports.getShortBranchName = exports.getFullBranchRef = exports.getBranchName = exports.getUserEmail = exports.getRecentCommitMessages = exports.getStagedChanges = exports.getChangesBetweenRefs = exports.getBranchChanges = exports.getChanges = exports.getUnstagedChanges = exports.fetchRemoteBranch = exports.fetchRemote = exports.getUntrackedChanges = void 0;
8
- const config_1 = require("./config");
9
- const git_1 = require("./git");
10
- const diffArgs = ["--no-pager", "diff", "--name-only", "--relative"];
5
+ "use strict";
6
+ Object.defineProperty(exports, "__esModule", {
7
+ value: true
8
+ });
9
+ function _export(target, all) {
10
+ for(var name in all)Object.defineProperty(target, name, {
11
+ enumerable: true,
12
+ get: Object.getOwnPropertyDescriptor(all, name).get
13
+ });
14
+ }
15
+ _export(exports, {
16
+ get commit () {
17
+ return commit;
18
+ },
19
+ get fetchRemote () {
20
+ return fetchRemote;
21
+ },
22
+ get fetchRemoteBranch () {
23
+ return fetchRemoteBranch;
24
+ },
25
+ get getBranchChanges () {
26
+ return getBranchChanges;
27
+ },
28
+ get getBranchName () {
29
+ return getBranchName;
30
+ },
31
+ get getChanges () {
32
+ return getChanges;
33
+ },
34
+ get getChangesBetweenRefs () {
35
+ return getChangesBetweenRefs;
36
+ },
37
+ get getCurrentHash () {
38
+ return getCurrentHash;
39
+ },
40
+ get getDefaultBranch () {
41
+ return getDefaultBranch;
42
+ },
43
+ get getFileAddedHash () {
44
+ return getFileAddedHash;
45
+ },
46
+ get getFullBranchRef () {
47
+ return getFullBranchRef;
48
+ },
49
+ get getParentBranch () {
50
+ return getParentBranch;
51
+ },
52
+ get getRecentCommitMessages () {
53
+ return getRecentCommitMessages;
54
+ },
55
+ get getRemoteBranch () {
56
+ return getRemoteBranch;
57
+ },
58
+ get getShortBranchName () {
59
+ return getShortBranchName;
60
+ },
61
+ get getStagedChanges () {
62
+ return getStagedChanges;
63
+ },
64
+ get getUnstagedChanges () {
65
+ return getUnstagedChanges;
66
+ },
67
+ get getUntrackedChanges () {
68
+ return getUntrackedChanges;
69
+ },
70
+ get getUserEmail () {
71
+ return getUserEmail;
72
+ },
73
+ get init () {
74
+ return init;
75
+ },
76
+ get listAllTrackedFiles () {
77
+ return listAllTrackedFiles;
78
+ },
79
+ get parseRemoteBranch () {
80
+ return parseRemoteBranch;
81
+ },
82
+ get revertLocalChanges () {
83
+ return revertLocalChanges;
84
+ },
85
+ get stage () {
86
+ return stage;
87
+ },
88
+ get stageAndCommit () {
89
+ return stageAndCommit;
90
+ }
91
+ });
92
+ const _config = require("./config.js");
93
+ const _git = require("./git.js");
94
+ const diffArgs = [
95
+ "--no-pager",
96
+ "diff",
97
+ "--name-only",
98
+ "--relative"
99
+ ];
11
100
  function getUntrackedChanges(cwdOrOptions) {
12
- const options = typeof cwdOrOptions === "string" ? { cwd: cwdOrOptions } : cwdOrOptions;
13
- const results = (0, git_1.git)(["ls-files", "--others", "--exclude-standard"], {
101
+ const options = typeof cwdOrOptions === "string" ? {
102
+ cwd: cwdOrOptions
103
+ } : cwdOrOptions;
104
+ const results = (0, _git.git)([
105
+ "ls-files",
106
+ "--others",
107
+ "--exclude-standard"
108
+ ], {
14
109
  description: "Gathering information about untracked changes",
15
110
  throwOnError: true,
16
- ...options,
111
+ ...options
112
+ });
113
+ return (0, _git.processGitOutput)(results, {
114
+ excludeNodeModules: true
17
115
  });
18
- return (0, git_1.processGitOutput)(results, { excludeNodeModules: true });
19
116
  }
20
- exports.getUntrackedChanges = getUntrackedChanges;
21
117
  function fetchRemote(remoteOrOptions, cwd) {
22
- const { remote, remoteBranch, options, ...gitOptions } = typeof remoteOrOptions === "string"
23
- ? ({ remote: remoteOrOptions, cwd: cwd })
24
- : remoteOrOptions;
118
+ const { remote, remoteBranch, options, ...gitOptions } = typeof remoteOrOptions === "string" ? {
119
+ remote: remoteOrOptions,
120
+ cwd: cwd
121
+ } : remoteOrOptions;
25
122
  if (remoteBranch && !remote) {
26
123
  throw new Error('Must provide "remote" when using "remoteBranch" option');
27
124
  }
28
125
  const fetchArgs = [
29
126
  "fetch",
30
127
  "--",
31
- ...(remote ? [remote] : []),
32
- ...(remoteBranch ? [remoteBranch] : []),
33
- ...(options || []),
128
+ ...remote ? [
129
+ remote
130
+ ] : [],
131
+ ...remoteBranch ? [
132
+ remoteBranch
133
+ ] : [],
134
+ ...options || []
34
135
  ];
35
- (0, git_1.git)(fetchArgs, {
36
- description: remote
37
- ? `Fetching ${remoteBranch ? `branch "${remoteBranch}" from ` : ""}remote "${remote}"`
38
- : "Fetching all remotes",
136
+ (0, _git.git)(fetchArgs, {
137
+ description: remote ? `Fetching ${remoteBranch ? `branch "${remoteBranch}" from ` : ""}remote "${remote}"` : "Fetching all remotes",
39
138
  throwOnError: true,
40
- ...gitOptions,
139
+ ...gitOptions
41
140
  });
42
141
  }
43
- exports.fetchRemote = fetchRemote;
44
- /**
45
- * Fetch from the given remote and branch. Throws an error on failure.
46
- * @deprecated Use `fetchRemote({ remote, remoteBranch, cwd })`
47
- */
48
- // TODO: move to fetch.ts
49
142
  function fetchRemoteBranch(remote, remoteBranch, cwd) {
50
- fetchRemote({ remote, remoteBranch, cwd, throwOnError: true });
143
+ fetchRemote({
144
+ remote,
145
+ remoteBranch,
146
+ cwd,
147
+ throwOnError: true
148
+ });
51
149
  }
52
- exports.fetchRemoteBranch = fetchRemoteBranch;
53
150
  function getUnstagedChanges(cwdOrOptions) {
54
- const options = typeof cwdOrOptions === "string" ? { cwd: cwdOrOptions } : cwdOrOptions;
55
- const results = (0, git_1.git)(diffArgs, {
151
+ const options = typeof cwdOrOptions === "string" ? {
152
+ cwd: cwdOrOptions
153
+ } : cwdOrOptions;
154
+ const results = (0, _git.git)(diffArgs, {
56
155
  description: "Gathering information about unstaged changes",
57
156
  throwOnError: true,
58
- ...options,
157
+ ...options
158
+ });
159
+ return (0, _git.processGitOutput)(results, {
160
+ excludeNodeModules: true
59
161
  });
60
- return (0, git_1.processGitOutput)(results, { excludeNodeModules: true });
61
162
  }
62
- exports.getUnstagedChanges = getUnstagedChanges;
63
- /**
64
- * Gets file paths with changes between the current branch and the given branch.
65
- * Throws an error on failure.
66
- *
67
- * @returns An array of relative file paths that have changed
68
- * @deprecated Use `getBranchChanges({ branch, cwd })`
69
- */
70
- // TODO: move to getChanges.ts
71
163
  function getChanges(branch, cwd) {
72
- return getChangesBetweenRefs({ fromRef: branch, cwd, throwOnError: true });
164
+ return getChangesBetweenRefs({
165
+ fromRef: branch,
166
+ cwd,
167
+ throwOnError: true
168
+ });
73
169
  }
74
- exports.getChanges = getChanges;
75
170
  function getBranchChanges(branchOrOptions, cwd) {
76
- const { branch, ...options } = typeof branchOrOptions === "string" ? { branch: branchOrOptions, cwd: cwd } : branchOrOptions;
77
- return getChangesBetweenRefs({ fromRef: branch, throwOnError: true, ...options });
171
+ const { branch, ...options } = typeof branchOrOptions === "string" ? {
172
+ branch: branchOrOptions,
173
+ cwd: cwd
174
+ } : branchOrOptions;
175
+ return getChangesBetweenRefs({
176
+ fromRef: branch,
177
+ throwOnError: true,
178
+ ...options
179
+ });
78
180
  }
79
- exports.getBranchChanges = getBranchChanges;
80
181
  function getChangesBetweenRefs(fromRef, toRef, options, pattern, cwd) {
81
182
  let gitOptions;
82
183
  if (typeof fromRef === "string") {
83
- gitOptions = { cwd: cwd };
84
- }
85
- else {
184
+ gitOptions = {
185
+ cwd: cwd
186
+ };
187
+ } else {
86
188
  ({ fromRef, toRef, options, pattern, ...gitOptions } = fromRef);
87
189
  }
88
190
  const range = `${fromRef}...${toRef || ""}`;
89
- const results = (0, git_1.git)([...diffArgs, ...(options || []), range, ...(pattern ? ["--", pattern] : [])], {
191
+ const results = (0, _git.git)([
192
+ ...diffArgs,
193
+ ...options || [],
194
+ range,
195
+ ...pattern ? [
196
+ "--",
197
+ pattern
198
+ ] : []
199
+ ], {
90
200
  description: `Gathering information about changes between refs (${range})`,
91
201
  throwOnError: true,
92
- ...gitOptions,
202
+ ...gitOptions
203
+ });
204
+ return (0, _git.processGitOutput)(results, {
205
+ excludeNodeModules: true
93
206
  });
94
- return (0, git_1.processGitOutput)(results, { excludeNodeModules: true });
95
207
  }
96
- exports.getChangesBetweenRefs = getChangesBetweenRefs;
97
208
  function getStagedChanges(cwdOrOptions) {
98
- const options = typeof cwdOrOptions === "string" ? { cwd: cwdOrOptions } : cwdOrOptions;
99
- const results = (0, git_1.git)([...diffArgs, "--staged"], {
209
+ const options = typeof cwdOrOptions === "string" ? {
210
+ cwd: cwdOrOptions
211
+ } : cwdOrOptions;
212
+ const results = (0, _git.git)([
213
+ ...diffArgs,
214
+ "--staged"
215
+ ], {
100
216
  description: "Gathering information about staged changes",
101
217
  throwOnError: true,
102
- ...options,
218
+ ...options
219
+ });
220
+ return (0, _git.processGitOutput)(results, {
221
+ excludeNodeModules: true
103
222
  });
104
- return (0, git_1.processGitOutput)(results, { excludeNodeModules: true });
105
223
  }
106
- exports.getStagedChanges = getStagedChanges;
107
224
  function getRecentCommitMessages(branchOrOptions, cwd) {
108
- const { branch, ...options } = typeof branchOrOptions === "string" ? { branch: branchOrOptions, cwd: cwd } : branchOrOptions;
109
- const results = (0, git_1.git)(["log", "--decorate", "--pretty=format:%s", `${branch}..HEAD`], {
225
+ const { branch, ...options } = typeof branchOrOptions === "string" ? {
226
+ branch: branchOrOptions,
227
+ cwd: cwd
228
+ } : branchOrOptions;
229
+ const results = (0, _git.git)([
230
+ "log",
231
+ "--decorate",
232
+ "--pretty=format:%s",
233
+ `${branch}..HEAD`
234
+ ], {
110
235
  description: `Getting recent commit messages for branch "${branch}"`,
111
- ...options,
236
+ ...options
112
237
  });
113
- return (0, git_1.processGitOutput)(results);
238
+ return (0, _git.processGitOutput)(results);
114
239
  }
115
- exports.getRecentCommitMessages = getRecentCommitMessages;
116
240
  function getUserEmail(cwdOrOptions) {
117
- const options = typeof cwdOrOptions === "string" ? { cwd: cwdOrOptions } : cwdOrOptions;
118
- return (0, config_1.getConfigValue)({ key: "user.email", ...options });
241
+ const options = typeof cwdOrOptions === "string" ? {
242
+ cwd: cwdOrOptions
243
+ } : cwdOrOptions;
244
+ return (0, _config.getConfigValue)({
245
+ key: "user.email",
246
+ ...options
247
+ });
119
248
  }
120
- exports.getUserEmail = getUserEmail;
121
249
  function getBranchName(cwdOrOptions) {
122
- const options = typeof cwdOrOptions === "string" ? { cwd: cwdOrOptions } : cwdOrOptions;
123
- const results = (0, git_1.git)(["rev-parse", "--abbrev-ref", "HEAD"], {
250
+ const options = typeof cwdOrOptions === "string" ? {
251
+ cwd: cwdOrOptions
252
+ } : cwdOrOptions;
253
+ const results = (0, _git.git)([
254
+ "rev-parse",
255
+ "--abbrev-ref",
256
+ "HEAD"
257
+ ], {
124
258
  description: "Getting current branch name",
125
- ...options,
259
+ ...options
126
260
  });
127
261
  return results.success ? results.stdout : null;
128
262
  }
129
- exports.getBranchName = getBranchName;
130
263
  function getFullBranchRef(branchOrOptions, cwd) {
131
- const { branch, ...options } = typeof branchOrOptions === "string" ? { branch: branchOrOptions, cwd: cwd } : branchOrOptions;
132
- const showRefResults = (0, git_1.git)(["show-ref", "--heads", branch], options);
264
+ const { branch, ...options } = typeof branchOrOptions === "string" ? {
265
+ branch: branchOrOptions,
266
+ cwd: cwd
267
+ } : branchOrOptions;
268
+ const showRefResults = (0, _git.git)([
269
+ "show-ref",
270
+ "--heads",
271
+ branch
272
+ ], options);
133
273
  return showRefResults.success ? showRefResults.stdout.split(" ")[1] : null;
134
274
  }
135
- exports.getFullBranchRef = getFullBranchRef;
136
275
  function getShortBranchName(refOrOptions, cwd) {
137
- const { fullBranchRef, ...options } = typeof refOrOptions === "string" ? { fullBranchRef: refOrOptions, cwd: cwd } : refOrOptions;
276
+ const { fullBranchRef, ...options } = typeof refOrOptions === "string" ? {
277
+ fullBranchRef: refOrOptions,
278
+ cwd: cwd
279
+ } : refOrOptions;
138
280
  // The original command `git name-rev --name-only` returned unreliable results if multiple
139
281
  // named refs point to the same commit as the branch.
140
- const showRefResults = (0, git_1.git)(["rev-parse", "--abbrev-ref", fullBranchRef], options);
282
+ const showRefResults = (0, _git.git)([
283
+ "rev-parse",
284
+ "--abbrev-ref",
285
+ fullBranchRef
286
+ ], options);
141
287
  return showRefResults.success ? showRefResults.stdout || null : null;
142
288
  }
143
- exports.getShortBranchName = getShortBranchName;
144
289
  function getCurrentHash(cwdOrOptions) {
145
- const options = typeof cwdOrOptions === "string" ? { cwd: cwdOrOptions } : cwdOrOptions;
146
- const results = (0, git_1.git)(["rev-parse", "HEAD"], {
290
+ const options = typeof cwdOrOptions === "string" ? {
291
+ cwd: cwdOrOptions
292
+ } : cwdOrOptions;
293
+ const results = (0, _git.git)([
294
+ "rev-parse",
295
+ "HEAD"
296
+ ], {
147
297
  description: "Getting current git hash",
148
- ...options,
298
+ ...options
149
299
  });
150
300
  return results.success ? results.stdout : null;
151
301
  }
152
- exports.getCurrentHash = getCurrentHash;
153
302
  function getFileAddedHash(filenameOrOptions, cwd) {
154
- const { filename, ...options } = typeof filenameOrOptions === "string" ? { filename: filenameOrOptions, cwd: cwd } : filenameOrOptions;
155
- const results = (0, git_1.git)(["rev-list", "--max-count=1", "HEAD", filename], options);
303
+ const { filename, ...options } = typeof filenameOrOptions === "string" ? {
304
+ filename: filenameOrOptions,
305
+ cwd: cwd
306
+ } : filenameOrOptions;
307
+ const results = (0, _git.git)([
308
+ "rev-list",
309
+ "--max-count=1",
310
+ "HEAD",
311
+ filename
312
+ ], options);
156
313
  return results.success ? results.stdout.trim() : undefined;
157
314
  }
158
- exports.getFileAddedHash = getFileAddedHash;
159
315
  function init(cwdOrOptions, _email, _username) {
160
- const { email, username, ...options } = typeof cwdOrOptions === "string" ? { cwd: cwdOrOptions, email: _email, username: _username } : cwdOrOptions;
161
- (0, git_1.git)(["init"], { ...options, throwOnError: true });
162
- if (!(0, config_1.getConfigValue)({ key: "user.name", ...options })) {
316
+ const { email, username, ...options } = typeof cwdOrOptions === "string" ? {
317
+ cwd: cwdOrOptions,
318
+ email: _email,
319
+ username: _username
320
+ } : cwdOrOptions;
321
+ (0, _git.git)([
322
+ "init"
323
+ ], {
324
+ ...options,
325
+ throwOnError: true
326
+ });
327
+ if (!(0, _config.getConfigValue)({
328
+ key: "user.name",
329
+ ...options
330
+ })) {
163
331
  if (!username) {
164
332
  throw new Error("must include a username when initializing git repo");
165
333
  }
166
- (0, git_1.git)(["config", "user.name", username], options);
334
+ (0, _git.git)([
335
+ "config",
336
+ "user.name",
337
+ username
338
+ ], options);
167
339
  }
168
340
  if (!getUserEmail(options)) {
169
341
  if (!email) {
170
342
  throw new Error("must include a email when initializing git repo");
171
343
  }
172
- (0, git_1.git)(["config", "user.email", email], options);
344
+ (0, _git.git)([
345
+ "config",
346
+ "user.email",
347
+ email
348
+ ], options);
173
349
  }
174
350
  }
175
- exports.init = init;
176
351
  function stage(patternsOrOptions, cwd) {
177
- const { patterns, ...options } = Array.isArray(patternsOrOptions)
178
- ? { patterns: patternsOrOptions, cwd: cwd }
179
- : patternsOrOptions;
180
- for (const pattern of patterns) {
181
- (0, git_1.git)(["add", pattern], { ...options, description: `Staging changes (git add ${pattern})` });
352
+ const { patterns, ...options } = Array.isArray(patternsOrOptions) ? {
353
+ patterns: patternsOrOptions,
354
+ cwd: cwd
355
+ } : patternsOrOptions;
356
+ for (const pattern of patterns){
357
+ (0, _git.git)([
358
+ "add",
359
+ pattern
360
+ ], {
361
+ ...options,
362
+ description: `Staging changes (git add ${pattern})`
363
+ });
182
364
  }
183
365
  }
184
- exports.stage = stage;
185
366
  function commit(messageOrOptions, _cwd, _options) {
186
- const { message, options, ...gitOptions } = typeof messageOrOptions === "string"
187
- ? { message: messageOrOptions, cwd: _cwd, options: _options }
188
- : messageOrOptions;
189
- (0, git_1.git)(["commit", "-m", message, ...(options || [])], {
367
+ const { message, options, ...gitOptions } = typeof messageOrOptions === "string" ? {
368
+ message: messageOrOptions,
369
+ cwd: _cwd,
370
+ options: _options
371
+ } : messageOrOptions;
372
+ (0, _git.git)([
373
+ "commit",
374
+ "-m",
375
+ message,
376
+ ...options || []
377
+ ], {
190
378
  throwOnError: true,
191
379
  description: "Committing changes",
192
- ...gitOptions,
380
+ ...gitOptions
193
381
  });
194
382
  }
195
- exports.commit = commit;
196
383
  function stageAndCommit(patternsOrOptions, message, cwd, commitOptions) {
197
- const options = Array.isArray(patternsOrOptions)
198
- ? { patterns: patternsOrOptions, message: message, cwd: cwd, options: commitOptions }
199
- : patternsOrOptions;
384
+ const options = Array.isArray(patternsOrOptions) ? {
385
+ patterns: patternsOrOptions,
386
+ message: message,
387
+ cwd: cwd,
388
+ options: commitOptions
389
+ } : patternsOrOptions;
200
390
  stage(options);
201
391
  commit(options);
202
392
  }
203
- exports.stageAndCommit = stageAndCommit;
204
393
  function revertLocalChanges(cwdOrOptions) {
205
- const options = typeof cwdOrOptions === "string" ? { cwd: cwdOrOptions } : cwdOrOptions;
394
+ const options = typeof cwdOrOptions === "string" ? {
395
+ cwd: cwdOrOptions
396
+ } : cwdOrOptions;
206
397
  const stash = `workspace-tools_${new Date().getTime()}`;
207
- if (!(0, git_1.git)(["stash", "push", "-u", "-m", stash], options).success) {
398
+ if (!(0, _git.git)([
399
+ "stash",
400
+ "push",
401
+ "-u",
402
+ "-m",
403
+ stash
404
+ ], options).success) {
208
405
  return false;
209
406
  }
210
- const results = (0, git_1.git)(["stash", "list"], options);
407
+ const results = (0, _git.git)([
408
+ "stash",
409
+ "list"
410
+ ], options);
211
411
  if (results.success) {
212
- const matched = results.stdout
213
- .split(/\n/)
214
- .find((line) => line.includes(stash))
215
- ?.match(/^[^:]+/);
412
+ const matched = results.stdout.split(/\n/).find((line)=>line.includes(stash))?.match(/^[^:]+/);
216
413
  if (matched) {
217
- (0, git_1.git)(["stash", "drop", matched[0]], options);
414
+ (0, _git.git)([
415
+ "stash",
416
+ "drop",
417
+ matched[0]
418
+ ], options);
218
419
  return true;
219
420
  }
220
421
  }
221
422
  return false;
222
423
  }
223
- exports.revertLocalChanges = revertLocalChanges;
224
- /**
225
- * Attempts to determine the parent branch of the current branch using `git show-branch`.
226
- * @returns The parent branch name if found, null otherwise
227
- * @deprecated Does not appear to be used
228
- */
229
424
  function getParentBranch(cwd) {
230
- const branchName = getBranchName({ cwd });
425
+ const branchName = getBranchName({
426
+ cwd
427
+ });
231
428
  if (!branchName || branchName === "HEAD") {
232
429
  return null;
233
430
  }
234
- const showBranchResult = (0, git_1.git)(["show-branch", "-a"], { cwd });
431
+ const showBranchResult = (0, _git.git)([
432
+ "show-branch",
433
+ "-a"
434
+ ], {
435
+ cwd
436
+ });
235
437
  if (showBranchResult.success) {
236
438
  const showBranchLines = showBranchResult.stdout.split(/\n/);
237
- const parentLine = showBranchLines.find((line) => line.includes("*") && !line.includes(branchName) && !line.includes("publish_"));
439
+ const parentLine = showBranchLines.find((line)=>line.includes("*") && !line.includes(branchName) && !line.includes("publish_"));
238
440
  const matched = parentLine?.match(/\[(.*)\]/);
239
441
  return matched ? matched[1] : null;
240
442
  }
241
443
  return null;
242
444
  }
243
- exports.getParentBranch = getParentBranch;
244
445
  function getRemoteBranch(branchOrOptions, cwd) {
245
- const options = typeof branchOrOptions === "string" ? { branch: branchOrOptions, cwd: cwd } : branchOrOptions;
246
- const results = (0, git_1.git)(["rev-parse", "--abbrev-ref", "--symbolic-full-name", `${options.branch}@\{u\}`], options);
446
+ const options = typeof branchOrOptions === "string" ? {
447
+ branch: branchOrOptions,
448
+ cwd: cwd
449
+ } : branchOrOptions;
450
+ const results = (0, _git.git)([
451
+ "rev-parse",
452
+ "--abbrev-ref",
453
+ "--symbolic-full-name",
454
+ `${options.branch}@{u}`
455
+ ], options);
247
456
  return results.success ? results.stdout.trim() : null;
248
457
  }
249
- exports.getRemoteBranch = getRemoteBranch;
250
458
  function parseRemoteBranch(branchOrOptions) {
251
459
  if (typeof branchOrOptions === "string") {
252
460
  const branch = branchOrOptions;
253
461
  const firstSlashPos = branch.indexOf("/", 0);
254
462
  return {
255
463
  remote: branch.substring(0, firstSlashPos),
256
- remoteBranch: branch.substring(firstSlashPos + 1),
464
+ remoteBranch: branch.substring(firstSlashPos + 1)
257
465
  };
258
466
  }
259
- const { branch, knownRemotes = ["origin", "upstream"], ...options } = branchOrOptions;
467
+ const { branch, knownRemotes = [
468
+ "origin",
469
+ "upstream"
470
+ ], ...options } = branchOrOptions;
260
471
  if (!branch.includes("/")) {
261
- return { remote: "", remoteBranch: branch };
472
+ return {
473
+ remote: "",
474
+ remoteBranch: branch
475
+ };
262
476
  }
263
- let remote = knownRemotes.find((remote) => branch.startsWith(`${remote}/`));
477
+ let remote = knownRemotes.find((r)=>branch.startsWith(`${r}/`));
264
478
  if (!remote) {
265
- const remotes = (0, git_1.git)(["remote"], options).stdout.trim().split(/\n/);
266
- remote = remotes.find((remote) => branch.startsWith(`${remote}/`));
479
+ const remotes = (0, _git.git)([
480
+ "remote"
481
+ ], options).stdout.trim().split(/\n/);
482
+ remote = remotes.find((r)=>branch.startsWith(`${r}/`));
267
483
  }
268
484
  if (remote) {
269
- return { remote, remoteBranch: branch.slice(remote.length + 1) };
485
+ return {
486
+ remote,
487
+ remoteBranch: branch.slice(remote.length + 1)
488
+ };
270
489
  }
271
- return { remote: "", remoteBranch: branch };
490
+ return {
491
+ remote: "",
492
+ remoteBranch: branch
493
+ };
272
494
  }
273
- exports.parseRemoteBranch = parseRemoteBranch;
274
495
  function getDefaultBranch(cwdOrOptions) {
275
- const options = typeof cwdOrOptions === "string" ? { cwd: cwdOrOptions } : cwdOrOptions;
496
+ const options = typeof cwdOrOptions === "string" ? {
497
+ cwd: cwdOrOptions
498
+ } : cwdOrOptions;
276
499
  // Default to the legacy 'master' for backwards compat and old git clients
277
- return (0, config_1.getConfigValue)({ key: "init.defaultBranch", ...options }) || "master";
500
+ return (0, _config.getConfigValue)({
501
+ key: "init.defaultBranch",
502
+ ...options
503
+ }) || "master";
278
504
  }
279
- exports.getDefaultBranch = getDefaultBranch;
280
505
  function listAllTrackedFiles(patternsOrOptions, cwd) {
281
- const { patterns, ...options } = Array.isArray(patternsOrOptions)
282
- ? { patterns: patternsOrOptions, cwd: cwd }
283
- : patternsOrOptions;
284
- const results = (0, git_1.git)(["ls-files", ...patterns], { throwOnError: true, ...options });
285
- return (0, git_1.processGitOutput)(results);
506
+ const { patterns, ...options } = Array.isArray(patternsOrOptions) ? {
507
+ patterns: patternsOrOptions,
508
+ cwd: cwd
509
+ } : patternsOrOptions;
510
+ const results = (0, _git.git)([
511
+ "ls-files",
512
+ ...patterns
513
+ ], {
514
+ throwOnError: true,
515
+ ...options
516
+ });
517
+ return (0, _git.processGitOutput)(results);
286
518
  }
287
- exports.listAllTrackedFiles = listAllTrackedFiles;
288
- //# sourceMappingURL=gitUtilities.js.map