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,50 +1,63 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getDefaultRemote = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- const path_1 = __importDefault(require("path"));
9
- const paths_1 = require("../paths");
10
- const getRepositoryName_1 = require("./getRepositoryName");
11
- const git_1 = require("./git");
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "getDefaultRemote", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return getDefaultRemote;
9
+ }
10
+ });
11
+ const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
12
+ const _path = /*#__PURE__*/ _interop_require_default(require("path"));
13
+ const _paths = require("../paths.js");
14
+ const _getRepositoryName = require("./getRepositoryName.js");
15
+ const _git = require("./git.js");
16
+ function _interop_require_default(obj) {
17
+ return obj && obj.__esModule ? obj : {
18
+ default: obj
19
+ };
20
+ }
12
21
  function getDefaultRemote(cwdOrOptions) {
13
- const options = typeof cwdOrOptions === "string" ? { cwd: cwdOrOptions } : cwdOrOptions;
22
+ const options = typeof cwdOrOptions === "string" ? {
23
+ cwd: cwdOrOptions
24
+ } : cwdOrOptions;
14
25
  const { cwd, strict, verbose } = options;
15
- const log = (message) => verbose && console.log(message);
16
- const logOrThrow = (message) => {
26
+ const log = (message)=>verbose && console.log(message);
27
+ const logOrThrow = (message)=>{
17
28
  if (strict) {
18
29
  throw new Error(message);
19
30
  }
20
31
  log(message);
21
32
  };
22
- const gitRoot = (0, paths_1.findGitRoot)(cwd);
33
+ const gitRoot = (0, _paths.findGitRoot)(cwd);
23
34
  let packageJson = {};
24
- const packageJsonPath = path_1.default.join(gitRoot, "package.json");
35
+ const packageJsonPath = _path.default.join(gitRoot, "package.json");
25
36
  try {
26
- packageJson = JSON.parse(fs_1.default.readFileSync(packageJsonPath, "utf8").trim());
27
- }
28
- catch (e) {
37
+ packageJson = JSON.parse(_fs.default.readFileSync(packageJsonPath, "utf8").trim());
38
+ } catch (e) {
29
39
  logOrThrow(`Could not read "${packageJsonPath}"`);
30
40
  }
31
41
  const { repository } = packageJson;
32
- const repositoryUrl = typeof repository === "string" ? repository : (repository && repository.url) || "";
42
+ const repositoryUrl = typeof repository === "string" ? repository : repository && repository.url || "";
33
43
  if (!repositoryUrl) {
34
44
  // This is always logged because it's strongly recommended to fix
35
45
  console.log(`Valid "repository" key not found in "${packageJsonPath}". Consider adding this info for more accurate git remote detection.`);
36
46
  }
37
- /** Repository full name (owner and repo name) specified in package.json */
38
- const repositoryName = (0, getRepositoryName_1.getRepositoryName)(repositoryUrl);
39
- const remotesResult = (0, git_1.git)(["remote", "-v"], { cwd });
47
+ /** Repository full name (owner and repo name) specified in package.json */ const repositoryName = (0, _getRepositoryName.getRepositoryName)(repositoryUrl);
48
+ const remotesResult = (0, _git.git)([
49
+ "remote",
50
+ "-v"
51
+ ], {
52
+ cwd
53
+ });
40
54
  if (!remotesResult.success) {
41
55
  logOrThrow(`Could not determine available git remotes under "${cwd}"`);
42
56
  }
43
- /** Mapping from remote URL to full name (owner and repo name) */
44
- const remotes = {};
45
- remotesResult.stdout.split("\n").forEach((line) => {
57
+ /** Mapping from remote URL to full name (owner and repo name) */ const remotes = {};
58
+ remotesResult.stdout.split("\n").forEach((line)=>{
46
59
  const [remoteName, remoteUrl] = line.split(/\s+/);
47
- const remoteRepoName = (0, getRepositoryName_1.getRepositoryName)(remoteUrl);
60
+ const remoteRepoName = (0, _getRepositoryName.getRepositoryName)(remoteUrl);
48
61
  if (remoteRepoName) {
49
62
  remotes[remoteRepoName] = remoteName;
50
63
  }
@@ -59,8 +72,12 @@ function getDefaultRemote(cwdOrOptions) {
59
72
  }
60
73
  // Default to upstream or origin if available, or the first remote otherwise
61
74
  const allRemoteNames = Object.values(remotes);
62
- const fallbacks = ["upstream", "origin", ...allRemoteNames];
63
- for (const fallback of fallbacks) {
75
+ const fallbacks = [
76
+ "upstream",
77
+ "origin",
78
+ ...allRemoteNames
79
+ ];
80
+ for (const fallback of fallbacks){
64
81
  if (allRemoteNames.includes(fallback)) {
65
82
  log(`Default to remote "${fallback}"`);
66
83
  return fallback;
@@ -73,5 +90,3 @@ function getDefaultRemote(cwdOrOptions) {
73
90
  log(`Assuming default remote "origin".`);
74
91
  return "origin";
75
92
  }
76
- exports.getDefaultRemote = getDefaultRemote;
77
- //# sourceMappingURL=getDefaultRemote.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getDefaultRemote.js","sourceRoot":"","sources":["../../src/git/getDefaultRemote.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AACxB,oCAAuC;AAEvC,2DAAwD;AACxD,+BAA4B;AA+B5B,SAAgB,gBAAgB,CAAC,YAA8C;IAC7E,MAAM,OAAO,GAAG,OAAO,YAAY,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,YAA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mC,CAAC,CAAC;IACzC,OAAO,QAAQ,CAAC;AAClB,CAAC;AA1ED,4CA0EC"}
1
+ {"version":3,"sources":["../../src/git/getDefaultRemote.ts"],"sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\nimport { findGitRoot } from \"../paths.js\";\nimport { type PackageInfo } from \"../types/PackageInfo.js\";\nimport { getRepositoryName } from \"./getRepositoryName.js\";\nimport { git } from \"./git.js\";\n\nexport type GetDefaultRemoteOptions = {\n /** Get repository info relative to this directory. */\n cwd: string;\n /**\n * If true, throw an error if remote info can't be found, or if a `repository` is not specified\n * in package.json and no matching remote is found.\n */\n strict?: boolean;\n /** If true, log debug messages about how the remote was chosen */\n verbose?: boolean;\n};\n\n/**\n * Get the name of the default remote: the one matching the `repository` field in package.json.\n * Throws if `options.cwd` is not in a git repo or there's no package.json at the repo root.\n *\n * The order of preference for returned remotes is:\n * 1. If `repository` is defined in package.json, the remote with a matching URL (if `options.strict`\n * is true, throws an error if no matching remote exists)\n * 2. `upstream` if defined\n * 3. `origin` if defined\n * 4. The first defined remote\n * 5. If there are no defined remotes: throws an error if `options.strict` is true; otherwise returns `origin`\n *\n * @returns The name of the inferred default remote.\n */\nexport function getDefaultRemote(options: GetDefaultRemoteOptions): string;\n/** @deprecated Use the object param version */\nexport function getDefaultRemote(cwd: string): string;\nexport function getDefaultRemote(cwdOrOptions: string | GetDefaultRemoteOptions): string {\n const options = typeof cwdOrOptions === \"string\" ? { cwd: cwdOrOptions } : cwdOrOptions;\n const { cwd, strict, verbose } = options;\n\n const log = (message: string) => verbose && console.log(message);\n const logOrThrow = (message: string) => {\n if (strict) {\n throw new Error(message);\n }\n log(message);\n };\n\n const gitRoot = findGitRoot(cwd);\n\n let packageJson: Partial<PackageInfo> = {};\n const packageJsonPath = path.join(gitRoot, \"package.json\");\n try {\n packageJson = JSON.parse(fs.readFileSync(packageJsonPath, \"utf8\").trim());\n } catch (e) {\n logOrThrow(`Could not read \"${packageJsonPath}\"`);\n }\n\n const { repository } = packageJson;\n const repositoryUrl = typeof repository === \"string\" ? repository : (repository && repository.url) || \"\";\n if (!repositoryUrl) {\n // This is always logged because it's strongly recommended to fix\n console.log(\n `Valid \"repository\" key not found in \"${packageJsonPath}\". Consider adding this info for more accurate git remote detection.`\n );\n }\n /** Repository full name (owner and repo name) specified in package.json */\n const repositoryName = getRepositoryName(repositoryUrl);\n\n const remotesResult = git([\"remote\", \"-v\"], { cwd });\n if (!remotesResult.success) {\n logOrThrow(`Could not determine available git remotes under \"${cwd}\"`);\n }\n\n /** Mapping from remote URL to full name (owner and repo name) */\n const remotes: { [remoteRepoUrl: string]: string } = {};\n remotesResult.stdout.split(\"\\n\").forEach((line) => {\n const [remoteName, remoteUrl] = line.split(/\\s+/);\n const remoteRepoName = getRepositoryName(remoteUrl);\n if (remoteRepoName) {\n remotes[remoteRepoName] = remoteName;\n }\n });\n\n if (repositoryName) {\n // If the repository name was found in package.json, check for a matching remote\n if (remotes[repositoryName]) {\n return remotes[repositoryName];\n }\n\n // If `strict` is true, and repositoryName is found, there MUST be a matching remote\n logOrThrow(`Could not find remote pointing to repository \"${repositoryName}\".`);\n }\n\n // Default to upstream or origin if available, or the first remote otherwise\n const allRemoteNames = Object.values(remotes);\n const fallbacks = [\"upstream\", \"origin\", ...allRemoteNames];\n for (const fallback of fallbacks) {\n if (allRemoteNames.includes(fallback)) {\n log(`Default to remote \"${fallback}\"`);\n return fallback;\n }\n }\n\n // If we get here, no git remotes were found. This should probably always be an error (since\n // subsequent operations which require a remote likely won't work), but to match old behavior,\n // still default to \"origin\" unless `strict` is true.\n logOrThrow(`Could not find any remotes in git repo at \"${gitRoot}\".`);\n log(`Assuming default remote \"origin\".`);\n return \"origin\";\n}\n"],"names":["getDefaultRemote","cwdOrOptions","options","cwd","strict","verbose","log","message","console","logOrThrow","Error","gitRoot","findGitRoot","packageJson","packageJsonPath","path","join","JSON","parse","fs","readFileSync","trim","e","repository","repositoryUrl","url","repositoryName","getRepositoryName","remotesResult","git","success","remotes","stdout","split","forEach","line","remoteName","remoteUrl","remoteRepoName","allRemoteNames","Object","values","fallbacks","fallback","includes"],"mappings":";;;;+BAoCgBA;;;eAAAA;;;2DApCD;6DACE;uBACW;mCAEM;qBACd;;;;;;AA+Bb,SAASA,iBAAiBC,YAA8C;IAC7E,MAAMC,UAAU,OAAOD,iBAAiB,WAAW;QAAEE,KAAKF;IAAa,IAAIA;IAC3E,MAAM,EAAEE,GAAG,EAAEC,MAAM,EAAEC,OAAO,EAAE,GAAGH;IAEjC,MAAMI,MAAM,CAACC,UAAoBF,WAAWG,QAAQF,GAAG,CAACC;IACxD,MAAME,aAAa,CAACF;QAClB,IAAIH,QAAQ;YACV,MAAM,IAAIM,MAAMH;QAClB;QACAD,IAAIC;IACN;IAEA,MAAMI,UAAUC,IAAAA,kBAAW,EAACT;IAE5B,IAAIU,cAAoC,CAAC;IACzC,MAAMC,kBAAkBC,aAAI,CAACC,IAAI,CAACL,SAAS;IAC3C,IAAI;QACFE,cAAcI,KAAKC,KAAK,CAACC,WAAE,CAACC,YAAY,CAACN,iBAAiB,QAAQO,IAAI;IACxE,EAAE,OAAOC,GAAG;QACVb,WAAW,CAAC,gBAAgB,EAAEK,gBAAgB,CAAC,CAAC;IAClD;IAEA,MAAM,EAAES,UAAU,EAAE,GAAGV;IACvB,MAAMW,gBAAgB,OAAOD,eAAe,WAAWA,aAAa,AAACA,cAAcA,WAAWE,GAAG,IAAK;IACtG,IAAI,CAACD,eAAe;QAClB,iEAAiE;QACjEhB,QAAQF,GAAG,CACT,CAAC,qCAAqC,EAAEQ,gBAAgB,oEAAoE,CAAC;IAEjI;IACA,yEAAyE,GACzE,MAAMY,iBAAiBC,IAAAA,oCAAiB,EAACH;IAEzC,MAAMI,gBAAgBC,IAAAA,QAAG,EAAC;QAAC;QAAU;KAAK,EAAE;QAAE1B;IAAI;IAClD,IAAI,CAACyB,cAAcE,OAAO,EAAE;QAC1BrB,WAAW,CAAC,iDAAiD,EAAEN,IAAI,CAAC,CAAC;IACvE;IAEA,+DAA+D,GAC/D,MAAM4B,UAA+C,CAAC;IACtDH,cAAcI,MAAM,CAACC,KAAK,CAAC,MAAMC,OAAO,CAAC,CAACC;QACxC,MAAM,CAACC,YAAYC,UAAU,GAAGF,KAAKF,KAAK,CAAC;QAC3C,MAAMK,iBAAiBX,IAAAA,oCAAiB,EAACU;QACzC,IAAIC,gBAAgB;YAClBP,OAAO,CAACO,eAAe,GAAGF;QAC5B;IACF;IAEA,IAAIV,gBAAgB;QAClB,gFAAgF;QAChF,IAAIK,OAAO,CAACL,eAAe,EAAE;YAC3B,OAAOK,OAAO,CAACL,eAAe;QAChC;QAEA,oFAAoF;QACpFjB,WAAW,CAAC,8CAA8C,EAAEiB,eAAe,EAAE,CAAC;IAChF;IAEA,4EAA4E;IAC5E,MAAMa,iBAAiBC,OAAOC,MAAM,CAACV;IACrC,MAAMW,YAAY;QAAC;QAAY;WAAaH;KAAe;IAC3D,KAAK,MAAMI,YAAYD,UAAW;QAChC,IAAIH,eAAeK,QAAQ,CAACD,WAAW;YACrCrC,IAAI,CAAC,mBAAmB,EAAEqC,SAAS,CAAC,CAAC;YACrC,OAAOA;QACT;IACF;IAEA,4FAA4F;IAC5F,8FAA8F;IAC9F,qDAAqD;IACrDlC,WAAW,CAAC,2CAA2C,EAAEE,QAAQ,EAAE,CAAC;IACpEL,IAAI,CAAC,iCAAiC,CAAC;IACvC,OAAO;AACT"}
@@ -1,4 +1,4 @@
1
- import { GetDefaultRemoteOptions } from "./getDefaultRemote";
1
+ import { type GetDefaultRemoteOptions } from "./getDefaultRemote.js";
2
2
  export type GetDefaultRemoteBranchOptions = GetDefaultRemoteOptions & {
3
3
  /** Name of branch to use. If undefined, uses the default branch name (falling back to `master`). */
4
4
  branch?: string;
@@ -1,37 +1,48 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDefaultRemoteBranch = void 0;
4
- const getDefaultRemote_1 = require("./getDefaultRemote");
5
- const git_1 = require("./git");
6
- const gitUtilities_1 = require("./gitUtilities");
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "getDefaultRemoteBranch", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return getDefaultRemoteBranch;
9
+ }
10
+ });
11
+ const _getDefaultRemote = require("./getDefaultRemote.js");
12
+ const _git = require("./git.js");
13
+ const _gitUtilities = require("./gitUtilities.js");
7
14
  function getDefaultRemoteBranch(...args) {
8
15
  const [branchOrOptions, argsCwd] = args;
9
- const options = typeof branchOrOptions === "string"
10
- ? { branch: branchOrOptions, cwd: argsCwd }
11
- : branchOrOptions;
16
+ const options = typeof branchOrOptions === "string" ? {
17
+ branch: branchOrOptions,
18
+ cwd: argsCwd
19
+ } : branchOrOptions;
12
20
  const { cwd, branch } = options;
13
- const defaultRemote = (0, getDefaultRemote_1.getDefaultRemote)(options);
21
+ const defaultRemote = (0, _getDefaultRemote.getDefaultRemote)(options);
14
22
  if (branch) {
15
23
  return `${defaultRemote}/${branch}`;
16
24
  }
17
- const showRemote = (0, git_1.git)(["remote", "show", defaultRemote], { cwd });
25
+ const showRemote = (0, _git.git)([
26
+ "remote",
27
+ "show",
28
+ defaultRemote
29
+ ], {
30
+ cwd
31
+ });
18
32
  let remoteDefaultBranch;
19
33
  if (showRemote.success) {
20
34
  /**
21
- * `showRemote.stdout` is something like this:
22
- *
23
- * * remote origin
24
- * Fetch URL: .../monorepo-upstream
25
- * Push URL: .../monorepo-upstream
26
- * HEAD branch: main
27
- */
28
- remoteDefaultBranch = showRemote.stdout
29
- .split(/\n/)
30
- .find((line) => line.includes("HEAD branch"))
31
- ?.replace(/^\s*HEAD branch:\s+/, "");
35
+ * `showRemote.stdout` is something like this:
36
+ *
37
+ * * remote origin
38
+ * Fetch URL: .../monorepo-upstream
39
+ * Push URL: .../monorepo-upstream
40
+ * HEAD branch: main
41
+ */ remoteDefaultBranch = showRemote.stdout.split(/\n/).find((line)=>line.includes("HEAD branch"))?.replace(/^\s*HEAD branch:\s+/, "");
32
42
  }
33
- remoteDefaultBranch || (remoteDefaultBranch = (0, gitUtilities_1.getDefaultBranch)({ cwd, throwOnError: options.strict }));
43
+ remoteDefaultBranch || (remoteDefaultBranch = (0, _gitUtilities.getDefaultBranch)({
44
+ cwd,
45
+ throwOnError: options.strict
46
+ }));
34
47
  return `${defaultRemote}/${remoteDefaultBranch}`;
35
48
  }
36
- exports.getDefaultRemoteBranch = getDefaultRemoteBranch;
37
- //# sourceMappingURL=getDefaultRemoteBranch.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getDefaultRemoteBranch.js","sourceRoot":"","sources":["../../src/git/getDefaultRemoteBranch.ts"],"names":[],"mappings":";;;AAAA,yDAA+E;AAC/E,+BAA4B;AAC5B,iDAAkD;AAoBlD,SAAgB,sBAAsB,CAAC,GAAG,IAAgD;IACxF,MAAM,CAAC,eAAe,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACxC,MAAM,OAAO,GACX,OAAO,eAAe,KAAK,QAAQ;QACjC,CAAC,CAAE,EAAE,MAAM,EAAE,eAAe,EAAE,GAAG,EAAE,OAAO,EAAoC;QAC9E,CAAC,CAAC,eAAe,CAAC;IACtB,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAEhC,MAAM,aAAa,GAAG,IAAA,mCAAgB,EAAC,OAAO,CAAC,CAAC;IAEhD,IAAI,MAAM,EAAE;QACV,OAAO,GAAG,aAAa,IAAI,MAAM,EAAE,CAAC;KACrC;IAED,MAAM,UAAU,GAAG,IAAA,SAAG,EAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;IACnE,IAAI,mBAAuC,CAAC;IAE5C,IAAI,UAAU,CAAC,OAAO,EAAE;QACtB;;;;;;;WAOG;QACH,mBAAmB,GAAG,UAAU,CAAC,MAAM;aACpC,KAAK,CAAC,IAAI,CAAC;aACX,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;YAC7C,EAAE,OAAO,CAAC,qBAAqB,EAAE,EAAE,CAAC,CAAC;KACxC;IAED,mBAAmB,KAAnB,mBAAmB,GAAK,IAAA,+BAAgB,EAAC,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,EAAC;IAEhF,OAAO,GAAG,aAAa,IAAI,mBAAmB,EAAE,CAAC;AACnD,CAAC;AAnCD,wDAmCC"}
1
+ {"version":3,"sources":["../../src/git/getDefaultRemoteBranch.ts"],"sourcesContent":["import { getDefaultRemote, type GetDefaultRemoteOptions } from \"./getDefaultRemote.js\";\nimport { git } from \"./git.js\";\nimport { getDefaultBranch } from \"./gitUtilities.js\";\n\nexport type GetDefaultRemoteBranchOptions = GetDefaultRemoteOptions & {\n /** Name of branch to use. If undefined, uses the default branch name (falling back to `master`). */\n branch?: string;\n};\n\n/**\n * Gets a reference to `options.branch` or the default branch relative to the default remote.\n * (See {@link getDefaultRemote} for how the default remote is determined.)\n * Throws if `options.cwd` is not in a git repo or there's no package.json at the repo root.\n * @returns A branch reference like `upstream/master` or `origin/master`.\n */\nexport function getDefaultRemoteBranch(options: GetDefaultRemoteBranchOptions): string;\n/**\n * First param: `branch`. Second param: `cwd`. See {@link GetDefaultRemoteBranchOptions} for more info.\n * (This had to be changed to `...args` to avoid a conflict with the object param version.)\n * @deprecated Use the object param version\n */\nexport function getDefaultRemoteBranch(...args: string[]): string;\nexport function getDefaultRemoteBranch(...args: (string | GetDefaultRemoteBranchOptions)[]): string {\n const [branchOrOptions, argsCwd] = args;\n const options =\n typeof branchOrOptions === \"string\"\n ? ({ branch: branchOrOptions, cwd: argsCwd } as GetDefaultRemoteBranchOptions)\n : branchOrOptions;\n const { cwd, branch } = options;\n\n const defaultRemote = getDefaultRemote(options);\n\n if (branch) {\n return `${defaultRemote}/${branch}`;\n }\n\n const showRemote = git([\"remote\", \"show\", defaultRemote], { cwd });\n let remoteDefaultBranch: string | undefined;\n\n if (showRemote.success) {\n /**\n * `showRemote.stdout` is something like this:\n *\n * * remote origin\n * Fetch URL: .../monorepo-upstream\n * Push URL: .../monorepo-upstream\n * HEAD branch: main\n */\n remoteDefaultBranch = showRemote.stdout\n .split(/\\n/)\n .find((line) => line.includes(\"HEAD branch\"))\n ?.replace(/^\\s*HEAD branch:\\s+/, \"\");\n }\n\n remoteDefaultBranch ||= getDefaultBranch({ cwd, throwOnError: options.strict });\n\n return `${defaultRemote}/${remoteDefaultBranch}`;\n}\n"],"names":["getDefaultRemoteBranch","args","branchOrOptions","argsCwd","options","branch","cwd","defaultRemote","getDefaultRemote","showRemote","git","remoteDefaultBranch","success","stdout","split","find","line","includes","replace","getDefaultBranch","throwOnError","strict"],"mappings":";;;;+BAsBgBA;;;eAAAA;;;kCAtB+C;qBAC3C;8BACa;AAoB1B,SAASA,uBAAuB,GAAGC,IAAgD;IACxF,MAAM,CAACC,iBAAiBC,QAAQ,GAAGF;IACnC,MAAMG,UACJ,OAAOF,oBAAoB,WACtB;QAAEG,QAAQH;QAAiBI,KAAKH;IAAQ,IACzCD;IACN,MAAM,EAAEI,GAAG,EAAED,MAAM,EAAE,GAAGD;IAExB,MAAMG,gBAAgBC,IAAAA,kCAAgB,EAACJ;IAEvC,IAAIC,QAAQ;QACV,OAAO,GAAGE,cAAc,CAAC,EAAEF,QAAQ;IACrC;IAEA,MAAMI,aAAaC,IAAAA,QAAG,EAAC;QAAC;QAAU;QAAQH;KAAc,EAAE;QAAED;IAAI;IAChE,IAAIK;IAEJ,IAAIF,WAAWG,OAAO,EAAE;QACtB;;;;;;;KAOC,GACDD,sBAAsBF,WAAWI,MAAM,CACpCC,KAAK,CAAC,MACNC,IAAI,CAAC,CAACC,OAASA,KAAKC,QAAQ,CAAC,iBAC5BC,QAAQ,uBAAuB;IACrC;IAEAP,wBAAAA,sBAAwBQ,IAAAA,8BAAgB,EAAC;QAAEb;QAAKc,cAAchB,QAAQiB,MAAM;IAAC;IAE7E,OAAO,GAAGd,cAAc,CAAC,EAAEI,qBAAqB;AAClD"}
@@ -3,7 +3,7 @@
3
3
  * including special handling for the many ADO/VSO URL formats.
4
4
  *
5
5
  * Examples:
6
- * - returns `microsoft/workspace-tools` for `https://github.com/microsoft/workspace-tools.git`
6
+ * - returns `microsoft/lage` for `https://github.com/microsoft/lage.git`
7
7
  * - returns `foo/bar/some-repo` for `https://dev.azure.com/foo/bar/_git/some-repo`
8
8
  */
9
9
  export declare function getRepositoryName(url: string): string;
@@ -1,18 +1,19 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getRepositoryName = void 0;
7
- const git_url_parse_1 = __importDefault(require("git-url-parse"));
8
- /**
9
- * Get a repository full name (owner and repo, plus organization for ADO/VSO) from a repository URL,
10
- * including special handling for the many ADO/VSO URL formats.
11
- *
12
- * Examples:
13
- * - returns `microsoft/workspace-tools` for `https://github.com/microsoft/workspace-tools.git`
14
- * - returns `foo/bar/some-repo` for `https://dev.azure.com/foo/bar/_git/some-repo`
15
- */
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "getRepositoryName", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return getRepositoryName;
9
+ }
10
+ });
11
+ const _giturlparse = /*#__PURE__*/ _interop_require_default(require("git-url-parse"));
12
+ function _interop_require_default(obj) {
13
+ return obj && obj.__esModule ? obj : {
14
+ default: obj
15
+ };
16
+ }
16
17
  function getRepositoryName(url) {
17
18
  try {
18
19
  // Mostly use this standard library, but fix some VSO/ADO-specific quirks to account for the
@@ -26,7 +27,7 @@ function getRepositoryName(url) {
26
27
  // https://dev.azure.com/foo/bar/_git/_optimized/some-repo
27
28
  // https://user@dev.azure.com/foo/bar/_git/some-repo
28
29
  // git@ssh.dev.azure.com:v3/foo/bar/some-repo
29
- const parsedUrl = (0, git_url_parse_1.default)(url.replace("/_optimized/", "/").replace("/DefaultCollection/", "/"));
30
+ const parsedUrl = (0, _giturlparse.default)(url.replace("/_optimized/", "/").replace("/DefaultCollection/", "/"));
30
31
  // `host` is set in `parse-url` but not documented... https://github.com/IonicaBizau/parse-url/blob/c830d48647f33c054745a916cf7c4c58722f4b25/src/index.js#L28
31
32
  const host = parsedUrl.host || "";
32
33
  const isVSO = host.endsWith(".visualstudio.com");
@@ -46,10 +47,7 @@ function getRepositoryName(url) {
46
47
  organization = host.match(/([^.@]+)\.visualstudio\.com$/)?.[1];
47
48
  }
48
49
  return `${organization}/${parsedUrl.owner}/${parsedUrl.name}`;
49
- }
50
- catch (err) {
50
+ } catch (err) {
51
51
  return "";
52
52
  }
53
53
  }
54
- exports.getRepositoryName = getRepositoryName;
55
- //# sourceMappingURL=getRepositoryName.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getRepositoryName.js","sourceRoot":"","sources":["../../src/git/getRepositoryName.ts"],"names":[],"mappings":";;;;;;AAAA,kEAAwC;AAExC;;;;;;;GAOG;AACH,SAAgB,iBAAiB,CAAC,GAAW;IAC3C,IAAI;QACF,4FAA4F;QAC5F,sFAAsF;QACtF,kDAAkD;QAClD,oEAAoE;QACpE,+EAA+E;QAC/E,+EAA+E;QAC/E,mDAAmD;QACnD,+CAA+C;QAC/C,0DAA0D;QAC1D,oDAAoD;QACpD,6CAA6C;QAC7C,MAAM,SAAS,GAAG,IAAA,uBAAW,EAAC,GAAG,CAAC,OAAO,CAAC,cAAc,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,qBAAqB,EAAE,GAAG,CAAC,CAAC,CAAC;QAEpG,6JAA6J;QAC7J,MAAM,IAAI,GAAY,SAAiB,CAAC,IAAI,IAAI,EAAE,CAAC;QACnD,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC;QACjD,IAAI,CAAC,KAAK,IAAI,IAAI,KAAK,eAAe,IAAI,IAAI,KAAK,mBAAmB,EAAE;YACtE,OAAO,SAAS,CAAC,SAAS,CAAC;SAC5B;QAED,kEAAkE;QAClE,MAAM,QAAQ,GAAG,SAAS,CAAC,SAAS,CAAC,KAAK,CACxC,yEAAyE,CAC1E,CAAC;QACF,IAAI,QAAQ,EAAE;YACZ,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,IAAI,EAAE,CAAC;SAC1D;QAED,oFAAoF;QACpF,8CAA8C;QAC9C,IAAI,YAAY,GAAuB,SAAS,CAAC,YAAY,CAAC;QAC9D,IAAI,CAAC,YAAY,IAAI,KAAK,EAAE;YAC1B,2CAA2C;YAC3C,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,8BAA8B,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;SAChE;QACD,OAAO,GAAG,YAAY,IAAI,SAAS,CAAC,KAAK,IAAI,SAAS,CAAC,IAAI,EAAE,CAAC;KAC/D;IAAC,OAAO,GAAG,EAAE;QACZ,OAAO,EAAE,CAAC;KACX;AACH,CAAC;AAzCD,8CAyCC"}
1
+ {"version":3,"sources":["../../src/git/getRepositoryName.ts"],"sourcesContent":["import gitUrlParse from \"git-url-parse\";\n\n/**\n * Get a repository full name (owner and repo, plus organization for ADO/VSO) from a repository URL,\n * including special handling for the many ADO/VSO URL formats.\n *\n * Examples:\n * - returns `microsoft/lage` for `https://github.com/microsoft/lage.git`\n * - returns `foo/bar/some-repo` for `https://dev.azure.com/foo/bar/_git/some-repo`\n */\nexport function getRepositoryName(url: string): string {\n try {\n // Mostly use this standard library, but fix some VSO/ADO-specific quirks to account for the\n // fact that all of the following URLs should be considered to point to the same repo:\n // https://foo.visualstudio.com/bar/_git/some-repo\n // https://foo.visualstudio.com/DefaultCollection/bar/_git/some-repo\n // https://user:token@foo.visualstudio.com/DefaultCollection/bar/_git/some-repo\n // https://foo.visualstudio.com/DefaultCollection/bar/_git/_optimized/some-repo\n // foo@vs-ssh.visualstudio.com:v3/foo/bar/some-repo\n // https://dev.azure.com/foo/bar/_git/some-repo\n // https://dev.azure.com/foo/bar/_git/_optimized/some-repo\n // https://user@dev.azure.com/foo/bar/_git/some-repo\n // git@ssh.dev.azure.com:v3/foo/bar/some-repo\n const parsedUrl = gitUrlParse(url.replace(\"/_optimized/\", \"/\").replace(\"/DefaultCollection/\", \"/\"));\n\n // `host` is set in `parse-url` but not documented... https://github.com/IonicaBizau/parse-url/blob/c830d48647f33c054745a916cf7c4c58722f4b25/src/index.js#L28\n const host: string = (parsedUrl as any).host || \"\";\n const isVSO = host.endsWith(\".visualstudio.com\");\n if (!isVSO && host !== \"dev.azure.com\" && host !== \"ssh.dev.azure.com\") {\n return parsedUrl.full_name;\n }\n\n // As of writing, ADO and VSO SSH URLs are parsed completely wrong\n const sshMatch = parsedUrl.full_name.match(\n /(vs-ssh\\.visualstudio\\.com|ssh\\.dev\\.azure\\.com):v\\d+\\/([^/]+)\\/([^/]+)/\n );\n if (sshMatch) {\n return `${sshMatch[2]}/${sshMatch[3]}/${parsedUrl.name}`;\n }\n\n // As of writing, full_name is wrong for enough variants of ADO and VSO URLs that it\n // makes more sense to just build it manually.\n let organization: string | undefined = parsedUrl.organization;\n if (!organization && isVSO) {\n // organization is missing or wrong for VSO\n organization = host.match(/([^.@]+)\\.visualstudio\\.com$/)?.[1];\n }\n return `${organization}/${parsedUrl.owner}/${parsedUrl.name}`;\n } catch (err) {\n return \"\";\n }\n}\n"],"names":["getRepositoryName","url","parsedUrl","gitUrlParse","replace","host","isVSO","endsWith","full_name","sshMatch","match","name","organization","owner","err"],"mappings":";;;;+BAUgBA;;;eAAAA;;;oEAVQ;;;;;;AAUjB,SAASA,kBAAkBC,GAAW;IAC3C,IAAI;QACF,4FAA4F;QAC5F,sFAAsF;QACtF,kDAAkD;QAClD,oEAAoE;QACpE,+EAA+E;QAC/E,+EAA+E;QAC/E,mDAAmD;QACnD,+CAA+C;QAC/C,0DAA0D;QAC1D,oDAAoD;QACpD,6CAA6C;QAC7C,MAAMC,YAAYC,IAAAA,oBAAW,EAACF,IAAIG,OAAO,CAAC,gBAAgB,KAAKA,OAAO,CAAC,uBAAuB;QAE9F,6JAA6J;QAC7J,MAAMC,OAAe,AAACH,UAAkBG,IAAI,IAAI;QAChD,MAAMC,QAAQD,KAAKE,QAAQ,CAAC;QAC5B,IAAI,CAACD,SAASD,SAAS,mBAAmBA,SAAS,qBAAqB;YACtE,OAAOH,UAAUM,SAAS;QAC5B;QAEA,kEAAkE;QAClE,MAAMC,WAAWP,UAAUM,SAAS,CAACE,KAAK,CACxC;QAEF,IAAID,UAAU;YACZ,OAAO,GAAGA,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAEA,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAEP,UAAUS,IAAI,EAAE;QAC1D;QAEA,oFAAoF;QACpF,8CAA8C;QAC9C,IAAIC,eAAmCV,UAAUU,YAAY;QAC7D,IAAI,CAACA,gBAAgBN,OAAO;YAC1B,2CAA2C;YAC3CM,eAAeP,KAAKK,KAAK,CAAC,iCAAiC,CAAC,EAAE;QAChE;QACA,OAAO,GAAGE,aAAa,CAAC,EAAEV,UAAUW,KAAK,CAAC,CAAC,EAAEX,UAAUS,IAAI,EAAE;IAC/D,EAAE,OAAOG,KAAK;QACZ,OAAO;IACT;AACF"}
package/lib/git/git.d.ts CHANGED
@@ -1,8 +1,5 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- /// <reference types="node" />
4
- import { SpawnSyncOptions, SpawnSyncReturns } from "child_process";
5
- import { GitCommonOptions } from "./types";
1
+ import { type SpawnSyncOptions, type SpawnSyncReturns } from "child_process";
2
+ import { type GitCommonOptions } from "./types.js";
6
3
  export type GitOptions = Omit<SpawnSyncOptions, "cwd"> & GitCommonOptions & {
7
4
  /** Operation description to be used in error message (formatted as start of sentence) */
8
5
  description?: string;
package/lib/git/git.js CHANGED
@@ -1,65 +1,86 @@
1
- "use strict";
2
1
  //
3
2
  // Basic git wrappers
4
3
  //
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.processGitOutput = exports.gitFailFast = exports.git = exports.clearGitObservers = exports.addGitObserver = exports.GitError = void 0;
7
- const child_process_1 = require("child_process");
4
+ "use strict";
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ function _export(target, all) {
9
+ for(var name in all)Object.defineProperty(target, name, {
10
+ enumerable: true,
11
+ get: Object.getOwnPropertyDescriptor(all, name).get
12
+ });
13
+ }
14
+ _export(exports, {
15
+ get GitError () {
16
+ return GitError;
17
+ },
18
+ get addGitObserver () {
19
+ return addGitObserver;
20
+ },
21
+ get clearGitObservers () {
22
+ return clearGitObservers;
23
+ },
24
+ get git () {
25
+ return git;
26
+ },
27
+ get gitFailFast () {
28
+ return gitFailFast;
29
+ },
30
+ get processGitOutput () {
31
+ return processGitOutput;
32
+ }
33
+ });
34
+ const _child_process = require("child_process");
35
+ function _define_property(obj, key, value) {
36
+ if (key in obj) {
37
+ Object.defineProperty(obj, key, {
38
+ value: value,
39
+ enumerable: true,
40
+ configurable: true,
41
+ writable: true
42
+ });
43
+ } else {
44
+ obj[key] = value;
45
+ }
46
+ return obj;
47
+ }
8
48
  class GitError extends Error {
9
- constructor(message, originalError, gitOutput) {
49
+ constructor(message, originalError, gitOutput){
10
50
  if (originalError instanceof Error) {
11
- super(`${message}: ${originalError.message}`);
12
- }
13
- else if (gitOutput?.stderr) {
14
- super(`${message} -- stderr:\n${gitOutput.stderr}`);
15
- }
16
- else {
17
- super(message);
51
+ super(`${message}: ${originalError.message}`), _define_property(this, "originalError", void 0), _define_property(this, "gitOutput", void 0);
52
+ } else if (gitOutput?.stderr) {
53
+ super(`${message} -- stderr:\n${gitOutput.stderr}`), _define_property(this, "originalError", void 0), _define_property(this, "gitOutput", void 0);
54
+ } else {
55
+ super(message), _define_property(this, "originalError", void 0), _define_property(this, "gitOutput", void 0);
18
56
  }
19
57
  this.originalError = originalError;
20
58
  this.gitOutput = gitOutput;
21
59
  }
22
60
  }
23
- exports.GitError = GitError;
24
61
  /**
25
62
  * A global maxBuffer override for all git operations.
26
63
  * Bumps up the default to 500MB instead of 1MB.
27
64
  * Override this value with the `GIT_MAX_BUFFER` environment variable.
28
- */
29
- const defaultMaxBuffer = process.env.GIT_MAX_BUFFER ? parseInt(process.env.GIT_MAX_BUFFER) : 500 * 1024 * 1024;
65
+ */ const defaultMaxBuffer = process.env.GIT_MAX_BUFFER ? parseInt(process.env.GIT_MAX_BUFFER) : 500 * 1024 * 1024;
30
66
  const isDebug = !!process.env.GIT_DEBUG;
31
67
  const observers = [];
32
68
  let observing;
33
- /**
34
- * Adds an observer for the git operations, e.g. for testing
35
- * @returns a function to remove the observer
36
- */
37
69
  function addGitObserver(observer) {
38
70
  observers.push(observer);
39
- return () => removeGitObserver(observer);
71
+ return ()=>removeGitObserver(observer);
40
72
  }
41
- exports.addGitObserver = addGitObserver;
42
- /** Clear all git observers */
43
73
  function clearGitObservers() {
44
74
  observers.splice(0, observers.length);
45
75
  }
46
- exports.clearGitObservers = clearGitObservers;
47
- /** Remove a git observer */
48
- function removeGitObserver(observer) {
76
+ /** Remove a git observer */ function removeGitObserver(observer) {
49
77
  const index = observers.indexOf(observer);
50
78
  if (index > -1) {
51
79
  observers.splice(index, 1);
52
80
  }
53
81
  }
54
- /**
55
- * Runs git command - use this for read-only commands, or if you'd like to explicitly check the
56
- * result and implement custom error handling.
57
- *
58
- * The caller is responsible for validating the input.
59
- * `shell` will always be set to false.
60
- */
61
82
  function git(args, options) {
62
- if (args.some((arg) => arg.startsWith("--upload-pack"))) {
83
+ if (args.some((arg)=>arg.startsWith("--upload-pack"))) {
63
84
  // This is a security issue and not needed for any expected usage of this library.
64
85
  throw new GitError("git command contains --upload-pack, which is not allowed: " + args.join(" "));
65
86
  }
@@ -69,9 +90,11 @@ function git(args, options) {
69
90
  let results;
70
91
  try {
71
92
  // this only throws if git isn't found or other rare cases
72
- results = (0, child_process_1.spawnSync)("git", args, { maxBuffer: defaultMaxBuffer, ...spawnOptions });
73
- }
74
- catch (e) {
93
+ results = (0, _child_process.spawnSync)("git", args, {
94
+ maxBuffer: defaultMaxBuffer,
95
+ ...spawnOptions
96
+ });
97
+ } catch (e) {
75
98
  throw new GitError(`${description} failed (while spawning process)`, e);
76
99
  }
77
100
  const output = {
@@ -79,7 +102,7 @@ function git(args, options) {
79
102
  // these may be undefined if stdio: inherit is set
80
103
  stderr: (results.stderr || "").toString().trimEnd(),
81
104
  stdout: (results.stdout || "").toString().trimEnd(),
82
- success: results.status === 0,
105
+ success: results.status === 0
83
106
  };
84
107
  if (debug) {
85
108
  console.log("exited with code " + results.status);
@@ -89,7 +112,7 @@ function git(args, options) {
89
112
  // notify observers, flipping the observing bit to prevent infinite loops
90
113
  if (!observing) {
91
114
  observing = true;
92
- for (const observer of observers) {
115
+ for (const observer of observers){
93
116
  observer(args, output);
94
117
  }
95
118
  observing = false;
@@ -99,14 +122,6 @@ function git(args, options) {
99
122
  }
100
123
  return output;
101
124
  }
102
- exports.git = git;
103
- /**
104
- * Run a git command. Use this for commands that make critical changes to the filesystem.
105
- * If it fails, throw an error and set `process.exitCode = 1` (unless `options.noExitCode` is set).
106
- *
107
- * The caller is responsible for validating the input.
108
- * `shell` will always be set to false.
109
- */
110
125
  function gitFailFast(args, options) {
111
126
  const gitResult = git(args, options);
112
127
  if (!gitResult.success) {
@@ -118,27 +133,10 @@ function gitFailFast(args, options) {
118
133
  ${gitResult.stderr?.toString().trimEnd()}`);
119
134
  }
120
135
  }
121
- exports.gitFailFast = gitFailFast;
122
- /**
123
- * Processes git command output by splitting it into lines and filtering out empty lines.
124
- * Also filters out `node_modules` lines if specified in options.
125
- *
126
- * If the command failed with stderr output, an error is thrown.
127
- *
128
- * @param output - The git command output to process
129
- * @returns An array of lines (presumably file paths), or an empty array if the command failed
130
- * without stderr output.
131
- * @internal
132
- */
133
136
  function processGitOutput(output, options) {
134
137
  if (!output.success) {
135
138
  // If the intent was to throw on failure, `throwOnError` should have been set for the git command.
136
139
  return [];
137
140
  }
138
- return output.stdout
139
- .split(/\n/)
140
- .map((line) => line.trim())
141
- .filter((line) => !!line && (!options?.excludeNodeModules || !line.includes("node_modules")));
141
+ return output.stdout.split(/\n/).map((line)=>line.trim()).filter((line)=>!!line && (!options?.excludeNodeModules || !line.includes("node_modules")));
142
142
  }
143
- exports.processGitOutput = processGitOutput;
144
- //# sourceMappingURL=git.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"git.js","sourceRoot":"","sources":["../../src/git/git.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,qBAAqB;AACrB,EAAE;;;AAEF,iDAA8E;AAU9E,MAAa,QAAS,SAAQ,KAAK;IAIjC,YAAY,OAAe,EAAE,aAAuB,EAAE,SAA4B;QAChF,IAAI,aAAa,YAAY,KAAK,EAAE;YAClC,KAAK,CAAC,GAAG,OAAO,KAAK,aAAa,CAAC,OAAO,EAAE,CAAC,CAAC;SAC/C;aAAM,IAAI,SAAS,EAAE,MAAM,EAAE;YAC5B,KAAK,CAAC,GAAG,OAAO,gBAAgB,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;SACrD;aAAM;YACL,KAAK,CAAC,OAAO,CAAC,CAAC;SAChB;QACD,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;CACF;AAfD,4BAeC;AAED;;;;GAIG;AACH,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC;AAE/G,MAAM,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC;AAUxC,MAAM,SAAS,GAAkB,EAAE,CAAC;AACpC,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,CAAC;KAC5G;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AA/CD,kBA+CC;AAED;;;;;;GAMG;AACH,SAAgB,WAAW,CAAC,IAAc,EAAE,OAAqD;IAC/F,MAAM,SAAS,GAAG,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACrC,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE;QACtB,IAAI,CAAC,OAAO,EAAE,UAAU,EAAE;YACxB,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;SACtB;QAED,MAAM,IAAI,QAAQ,CAAC,4CAA4C,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;MAC3E,SAAS,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC,OAAO,EAAE;MACtC,SAAS,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;KAC7C;AACH,CAAC;AAXD,kCAWC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,gBAAgB,CAAC,MAAwB,EAAE,OAA0C;IACnG,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE;QACnB,kGAAkG;QAClG,OAAO,EAAE,CAAC;KACX;IAED,OAAO,MAAM,CAAC,MAAM;SACjB,KAAK,CAAC,IAAI,CAAC;SACX,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;SAC1B,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,OAAO,EAAE,kBAAkB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;AAClG,CAAC;AAVD,4CAUC"}
1
+ {"version":3,"sources":["../../src/git/git.ts"],"sourcesContent":["//\n// Basic git wrappers\n//\n\nimport { spawnSync, type SpawnSyncOptions, type SpawnSyncReturns } from \"child_process\";\nimport { type GitCommonOptions } from \"./types.js\";\n\nexport type GitOptions = Omit<SpawnSyncOptions, \"cwd\"> &\n GitCommonOptions & {\n /** Operation description to be used in error message (formatted as start of sentence) */\n description?: string;\n debug?: boolean;\n };\n\nexport class GitError extends Error {\n public readonly originalError: unknown;\n public readonly gitOutput?: GitProcessOutput;\n\n constructor(message: string, originalError?: unknown, gitOutput?: GitProcessOutput) {\n if (originalError instanceof Error) {\n super(`${message}: ${originalError.message}`);\n } else if (gitOutput?.stderr) {\n super(`${message} -- stderr:\\n${gitOutput.stderr}`);\n } else {\n super(message);\n }\n this.originalError = originalError;\n this.gitOutput = gitOutput;\n }\n}\n\n/**\n * A global maxBuffer override for all git operations.\n * Bumps up the default to 500MB instead of 1MB.\n * Override this value with the `GIT_MAX_BUFFER` environment variable.\n */\nconst defaultMaxBuffer = process.env.GIT_MAX_BUFFER ? parseInt(process.env.GIT_MAX_BUFFER) : 500 * 1024 * 1024;\n\nconst isDebug = !!process.env.GIT_DEBUG;\n\nexport type GitProcessOutput = {\n stderr: string;\n stdout: string;\n success: boolean;\n} & Omit<SpawnSyncReturns<string | Buffer>, \"stdout\" | \"stderr\">;\n\n/** Observes the git operations called from `git()` or `gitFailFast()` */\nexport type GitObserver = (args: string[], output: GitProcessOutput) => void;\nconst observers: GitObserver[] = [];\nlet observing: boolean;\n\n/**\n * Adds an observer for the git operations, e.g. for testing\n * @returns a function to remove the observer\n */\nexport function addGitObserver(observer: GitObserver): () => void {\n observers.push(observer);\n return () => removeGitObserver(observer);\n}\n\n/** Clear all git observers */\nexport function clearGitObservers(): void {\n observers.splice(0, observers.length);\n}\n\n/** Remove a git observer */\nfunction removeGitObserver(observer: GitObserver): void {\n const index = observers.indexOf(observer);\n if (index > -1) {\n observers.splice(index, 1);\n }\n}\n\n/**\n * Runs git command - use this for read-only commands, or if you'd like to explicitly check the\n * result and implement custom error handling.\n *\n * The caller is responsible for validating the input.\n * `shell` will always be set to false.\n */\nexport function git(args: string[], options?: GitOptions): GitProcessOutput {\n if (args.some((arg) => arg.startsWith(\"--upload-pack\"))) {\n // This is a security issue and not needed for any expected usage of this library.\n throw new GitError(\"git command contains --upload-pack, which is not allowed: \" + args.join(\" \"));\n }\n\n const gitDescription = `git ${args.join(\" \")}`;\n const { throwOnError, description = gitDescription, debug = isDebug, ...spawnOptions } = options || {};\n\n debug && console.log(gitDescription);\n\n let results: SpawnSyncReturns<string | Buffer>;\n try {\n // this only throws if git isn't found or other rare cases\n results = spawnSync(\"git\", args, { maxBuffer: defaultMaxBuffer, ...spawnOptions });\n } catch (e) {\n throw new GitError(`${description} failed (while spawning process)`, e);\n }\n\n const output: GitProcessOutput = {\n ...results,\n // these may be undefined if stdio: inherit is set\n stderr: (results.stderr || \"\").toString().trimEnd(),\n stdout: (results.stdout || \"\").toString().trimEnd(),\n success: results.status === 0,\n };\n\n if (debug) {\n console.log(\"exited with code \" + results.status);\n output.stdout && console.log(\"git stdout:\\n\", output.stdout);\n output.stderr && console.warn(\"git stderr:\\n\", output.stderr);\n }\n\n // notify observers, flipping the observing bit to prevent infinite loops\n if (!observing) {\n observing = true;\n for (const observer of observers) {\n observer(args, output);\n }\n observing = false;\n }\n\n if (!output.success && throwOnError) {\n throw new GitError(`${description} failed${output.stderr ? `\\n${output.stderr}` : \"\"}`, undefined, output);\n }\n\n return output;\n}\n\n/**\n * Run a git command. Use this for commands that make critical changes to the filesystem.\n * If it fails, throw an error and set `process.exitCode = 1` (unless `options.noExitCode` is set).\n *\n * The caller is responsible for validating the input.\n * `shell` will always be set to false.\n */\nexport function gitFailFast(args: string[], options?: GitCommonOptions & { noExitCode?: boolean }): void {\n const gitResult = git(args, options);\n if (!gitResult.success) {\n if (!options?.noExitCode) {\n process.exitCode = 1;\n }\n\n throw new GitError(`CRITICAL ERROR: running git command: git ${args.join(\" \")}!\n ${gitResult.stdout?.toString().trimEnd()}\n ${gitResult.stderr?.toString().trimEnd()}`);\n }\n}\n\n/**\n * Processes git command output by splitting it into lines and filtering out empty lines.\n * Also filters out `node_modules` lines if specified in options.\n *\n * If the command failed with stderr output, an error is thrown.\n *\n * @param output - The git command output to process\n * @returns An array of lines (presumably file paths), or an empty array if the command failed\n * without stderr output.\n * @internal\n */\nexport function processGitOutput(output: GitProcessOutput, options?: { excludeNodeModules?: boolean }): string[] {\n if (!output.success) {\n // If the intent was to throw on failure, `throwOnError` should have been set for the git command.\n return [];\n }\n\n return output.stdout\n .split(/\\n/)\n .map((line) => line.trim())\n .filter((line) => !!line && (!options?.excludeNodeModules || !line.includes(\"node_modules\")));\n}\n"],"names":["GitError","addGitObserver","clearGitObservers","git","gitFailFast","processGitOutput","Error","message","originalError","gitOutput","stderr","defaultMaxBuffer","process","env","GIT_MAX_BUFFER","parseInt","isDebug","GIT_DEBUG","observers","observing","observer","push","removeGitObserver","splice","length","index","indexOf","args","options","some","arg","startsWith","join","gitDescription","throwOnError","description","debug","spawnOptions","console","log","results","spawnSync","maxBuffer","e","output","toString","trimEnd","stdout","success","status","warn","undefined","gitResult","noExitCode","exitCode","split","map","line","trim","filter","excludeNodeModules","includes"],"mappings":"AAAA,EAAE;AACF,qBAAqB;AACrB,EAAE;;;;;;;;;;;;QAYWA;eAAAA;;QAyCGC;eAAAA;;QAMAC;eAAAA;;QAmBAC;eAAAA;;QAwDAC;eAAAA;;QAwBAC;eAAAA;;;+BA5JwD;;;;;;;;;;;;;;AAUjE,MAAML,iBAAiBM;IAI5B,YAAYC,OAAe,EAAEC,aAAuB,EAAEC,SAA4B,CAAE;QAClF,IAAID,yBAAyBF,OAAO;YAClC,KAAK,CAAC,GAAGC,QAAQ,EAAE,EAAEC,cAAcD,OAAO,EAAE,GALhD,uBAAgBC,iBAAhB,KAAA,IACA,uBAAgBC,aAAhB,KAAA;QAKE,OAAO,IAAIA,WAAWC,QAAQ;YAC5B,KAAK,CAAC,GAAGH,QAAQ,aAAa,EAAEE,UAAUC,MAAM,EAAE,GAPtD,uBAAgBF,iBAAhB,KAAA,IACA,uBAAgBC,aAAhB,KAAA;QAOE,OAAO;YACL,KAAK,CAACF,UATV,uBAAgBC,iBA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AACF;AAaO,SAASzC,iBAAiBuC,MAAwB,EAAEhB,OAA0C;IACnG,IAAI,CAACgB,OAAOI,OAAO,EAAE;QACnB,kGAAkG;QAClG,OAAO,EAAE;IACX;IAEA,OAAOJ,OAAOG,MAAM,CACjBQ,KAAK,CAAC,MACNC,GAAG,CAAC,CAACC,OAASA,KAAKC,IAAI,IACvBC,MAAM,CAAC,CAACF,OAAS,CAAC,CAACA,QAAS,CAAA,CAAC7B,SAASgC,sBAAsB,CAACH,KAAKI,QAAQ,CAAC,eAAc;AAC9F"}
@@ -1,4 +1,4 @@
1
- import type { GetChangesBetweenRefsOptions, GitBranchOptions, GitCommitOptions, GitCommonOptions, GitFetchOptions, GitInitOptions, GitStageOptions, ParsedRemoteBranch, ParseRemoteBranchOptions } from "./types";
1
+ import type { GetChangesBetweenRefsOptions, GitBranchOptions, GitCommitOptions, GitCommonOptions, GitFetchOptions, GitInitOptions, GitStageOptions, ParsedRemoteBranch, ParseRemoteBranchOptions } from "./types.js";
2
2
  /**
3
3
  * Get a list of files with untracked changes.
4
4
  * Throws an error on failure by default.
@@ -86,9 +86,9 @@ export declare function getUserEmail(cwd: string): string | null;
86
86
  *
87
87
  * @returns The branch name if successful, null otherwise
88
88
  */
89
- export declare function getBranchName(options: GitCommonOptions): string;
89
+ export declare function getBranchName(options: GitCommonOptions): string | null;
90
90
  /** @deprecated Use object params version */
91
- export declare function getBranchName(cwd: string): string;
91
+ export declare function getBranchName(cwd: string): string | null;
92
92
  /**
93
93
  * Gets the full reference path for a given branch.
94
94
  * `branch` here is the short branch name, e.g. `branch-name`.