workspace-tools 0.40.4 → 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 (186) hide show
  1. package/README.md +39 -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 +7 -5
  9. package/lib/getPackageInfo.js +46 -39
  10. package/lib/getPackageInfo.js.map +1 -1
  11. package/lib/getPackageInfos.d.ts +31 -8
  12. package/lib/getPackageInfos.js +41 -41
  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 +12 -2
  37. package/lib/graph/createDependencyMap.js +18 -10
  38. package/lib/graph/createDependencyMap.js.map +1 -1
  39. package/lib/graph/createPackageGraph.d.ts +10 -6
  40. package/lib/graph/createPackageGraph.js +58 -42
  41. package/lib/graph/createPackageGraph.js.map +1 -1
  42. package/lib/graph/getPackageDependencies.d.ts +2 -2
  43. package/lib/graph/getPackageDependencies.js +24 -53
  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 -27
  49. package/lib/index.js +154 -75
  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 +4 -1
  77. package/lib/paths.js +60 -58
  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.d.ts +5 -1
  84. package/lib/types/PackageGraph.js +4 -3
  85. package/lib/types/PackageGraph.js.map +1 -1
  86. package/lib/types/PackageInfo.d.ts +1 -1
  87. package/lib/types/PackageInfo.js +3 -2
  88. package/lib/types/PackageInfo.js.map +1 -1
  89. package/lib/types/WorkspaceInfo.d.ts +3 -5
  90. package/lib/types/WorkspaceInfo.js +3 -2
  91. package/lib/types/WorkspaceInfo.js.map +1 -1
  92. package/lib/types/WorkspaceManager.js +4 -0
  93. package/lib/types/WorkspaceManager.js.map +1 -0
  94. package/lib/workspaces/catalogsToYaml.d.ts +1 -1
  95. package/lib/workspaces/catalogsToYaml.js +12 -10
  96. package/lib/workspaces/catalogsToYaml.js.map +1 -1
  97. package/lib/workspaces/findWorkspacePath.d.ts +2 -1
  98. package/lib/workspaces/findWorkspacePath.js +10 -12
  99. package/lib/workspaces/findWorkspacePath.js.map +1 -1
  100. package/lib/workspaces/getAllPackageJsonFiles.d.ts +10 -4
  101. package/lib/workspaces/getAllPackageJsonFiles.js +32 -22
  102. package/lib/workspaces/getAllPackageJsonFiles.js.map +1 -1
  103. package/lib/workspaces/getCatalogVersion.d.ts +1 -1
  104. package/lib/workspaces/getCatalogVersion.js +19 -32
  105. package/lib/workspaces/getCatalogVersion.js.map +1 -1
  106. package/lib/workspaces/getCatalogs.d.ts +8 -2
  107. package/lib/workspaces/getCatalogs.js +23 -15
  108. package/lib/workspaces/getCatalogs.js.map +1 -1
  109. package/lib/workspaces/getChangedPackages.d.ts +1 -1
  110. package/lib/workspaces/getChangedPackages.js +47 -30
  111. package/lib/workspaces/getChangedPackages.js.map +1 -1
  112. package/lib/workspaces/getPackagesByFiles.js +29 -24
  113. package/lib/workspaces/getPackagesByFiles.js.map +1 -1
  114. package/lib/workspaces/getWorkspaceInfos.d.ts +36 -0
  115. package/lib/workspaces/getWorkspaceInfos.js +60 -0
  116. package/lib/workspaces/getWorkspaceInfos.js.map +1 -0
  117. package/lib/workspaces/getWorkspaceManagerRoot.d.ts +16 -0
  118. package/lib/workspaces/getWorkspaceManagerRoot.js +32 -0
  119. package/lib/workspaces/getWorkspaceManagerRoot.js.map +1 -0
  120. package/lib/workspaces/getWorkspacePackagePaths.d.ts +17 -2
  121. package/lib/workspaces/getWorkspacePackagePaths.js +138 -24
  122. package/lib/workspaces/getWorkspacePackagePaths.js.map +1 -1
  123. package/lib/workspaces/getWorkspacePatterns.d.ts +11 -0
  124. package/lib/workspaces/getWorkspacePatterns.js +25 -0
  125. package/lib/workspaces/getWorkspacePatterns.js.map +1 -0
  126. package/lib/workspaces/implementations/WorkspaceUtilities.d.ts +27 -0
  127. package/lib/workspaces/implementations/WorkspaceUtilities.js +4 -0
  128. package/lib/workspaces/implementations/WorkspaceUtilities.js.map +1 -0
  129. package/lib/workspaces/implementations/getPackageJsonWorkspacePatterns.d.ts +9 -0
  130. package/lib/workspaces/implementations/getPackageJsonWorkspacePatterns.js +38 -0
  131. package/lib/workspaces/implementations/getPackageJsonWorkspacePatterns.js.map +1 -0
  132. package/lib/workspaces/implementations/getWorkspaceManagerAndRoot.d.ts +19 -5
  133. package/lib/workspaces/implementations/getWorkspaceManagerAndRoot.js +38 -40
  134. package/lib/workspaces/implementations/getWorkspaceManagerAndRoot.js.map +1 -1
  135. package/lib/workspaces/implementations/getWorkspaceUtilities.d.ts +4 -36
  136. package/lib/workspaces/implementations/getWorkspaceUtilities.js +35 -20
  137. package/lib/workspaces/implementations/getWorkspaceUtilities.js.map +1 -1
  138. package/lib/workspaces/implementations/index.d.ts +2 -2
  139. package/lib/workspaces/implementations/index.js +19 -7
  140. package/lib/workspaces/implementations/index.js.map +1 -1
  141. package/lib/workspaces/implementations/lerna.d.ts +2 -20
  142. package/lib/workspaces/implementations/lerna.js +77 -62
  143. package/lib/workspaces/implementations/lerna.js.map +1 -1
  144. package/lib/workspaces/implementations/npm.d.ts +3 -17
  145. package/lib/workspaces/implementations/npm.js +12 -43
  146. package/lib/workspaces/implementations/npm.js.map +1 -1
  147. package/lib/workspaces/implementations/pnpm.d.ts +2 -30
  148. package/lib/workspaces/implementations/pnpm.js +32 -89
  149. package/lib/workspaces/implementations/pnpm.js.map +1 -1
  150. package/lib/workspaces/implementations/rush.d.ts +2 -22
  151. package/lib/workspaces/implementations/rush.js +26 -69
  152. package/lib/workspaces/implementations/rush.js.map +1 -1
  153. package/lib/workspaces/implementations/yarn.d.ts +2 -35
  154. package/lib/workspaces/implementations/yarn.js +33 -85
  155. package/lib/workspaces/implementations/yarn.js.map +1 -1
  156. package/lib/workspaces/wrapWorkspaceUtility.d.ts +31 -0
  157. package/lib/workspaces/wrapWorkspaceUtility.js +47 -0
  158. package/lib/workspaces/wrapWorkspaceUtility.js.map +1 -0
  159. package/package.json +21 -12
  160. package/lib/getPackagePaths.d.ts +0 -10
  161. package/lib/getPackagePaths.js +0 -49
  162. package/lib/getPackagePaths.js.map +0 -1
  163. package/lib/infoFromPackageJson.d.ts +0 -17
  164. package/lib/infoFromPackageJson.js +0 -11
  165. package/lib/infoFromPackageJson.js.map +0 -1
  166. package/lib/lockfile/index.d.ts +0 -6
  167. package/lib/lockfile/index.js +0 -105
  168. package/lib/lockfile/index.js.map +0 -1
  169. package/lib/workspaces/WorkspaceManager.js +0 -3
  170. package/lib/workspaces/WorkspaceManager.js.map +0 -1
  171. package/lib/workspaces/getWorkspacePackageInfo.d.ts +0 -26
  172. package/lib/workspaces/getWorkspacePackageInfo.js +0 -76
  173. package/lib/workspaces/getWorkspacePackageInfo.js.map +0 -1
  174. package/lib/workspaces/getWorkspaceRoot.d.ts +0 -25
  175. package/lib/workspaces/getWorkspaceRoot.js +0 -35
  176. package/lib/workspaces/getWorkspaceRoot.js.map +0 -1
  177. package/lib/workspaces/getWorkspaces.d.ts +0 -20
  178. package/lib/workspaces/getWorkspaces.js +0 -39
  179. package/lib/workspaces/getWorkspaces.js.map +0 -1
  180. package/lib/workspaces/implementations/packageJsonWorkspaces.d.ts +0 -31
  181. package/lib/workspaces/implementations/packageJsonWorkspaces.js +0 -104
  182. package/lib/workspaces/implementations/packageJsonWorkspaces.js.map +0 -1
  183. package/lib/workspaces/listOfWorkspacePackageNames.d.ts +0 -5
  184. package/lib/workspaces/listOfWorkspacePackageNames.js +0 -11
  185. package/lib/workspaces/listOfWorkspacePackageNames.js.map +0 -1
  186. /package/lib/{workspaces → types}/WorkspaceManager.d.ts +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"getCatalogs.js","sourceRoot":"","sources":["../../src/workspaces/getCatalogs.ts"],"names":[],"mappings":";;;AACA,uDAA0D;AAE1D;;;;;;GAMG;AACH,SAAgB,WAAW,CAAC,GAAW;IACrC,MAAM,KAAK,GAAG,IAAA,uCAAqB,EAAC,GAAG,CAAC,CAAC;IACzC,OAAO,KAAK,EAAE,WAAW,EAAE,CAAC,GAAG,CAAC,CAAC;AACnC,CAAC;AAHD,kCAGC"}
1
+ {"version":3,"sources":["../../src/workspaces/getCatalogs.ts"],"sourcesContent":["import type { Catalogs } from \"../types/Catalogs.js\";\nimport type { WorkspaceManager } from \"../types/WorkspaceManager.js\";\nimport { getWorkspaceUtilities } from \"./implementations\";\nimport { wrapWorkspaceUtility } from \"./wrapWorkspaceUtility.js\";\n\n/**\n * Get version catalogs, if supported by the manager (only pnpm and yarn v4 as of writing).\n * Returns undefined if no catalogs are present or the manager doesn't support them.\n * @see https://pnpm.io/catalogs\n * @see https://yarnpkg.com/features/catalogs\n *\n * @param cwd - Current working directory. It will search up from here to find the root, with caching.\n * @param managerOverride Workspace/monorepo manager to use instead of auto-detecting\n *\n * @returns Catalogs if defined, or undefined if not available\n * (logs verbose warnings instead of throwing on error)\n */\nexport function getCatalogs(cwd: string, managerOverride?: WorkspaceManager): Catalogs | undefined {\n return wrapWorkspaceUtility({\n cwd,\n managerOverride,\n description: \"catalogs\",\n impl: ({ manager, root }) => {\n // There is no default implementation for catalogs, since not all managers support it\n return getWorkspaceUtilities(manager).getCatalogs?.({ root });\n },\n });\n}\n"],"names":["getCatalogs","cwd","managerOverride","wrapWorkspaceUtility","description","impl","manager","root","getWorkspaceUtilities"],"mappings":";;;;+BAiBgBA;;;eAAAA;;;iCAfsB;sCACD;AAc9B,SAASA,YAAYC,GAAW,EAAEC,eAAkC;IACzE,OAAOC,IAAAA,0CAAoB,EAAC;QAC1BF;QACAC;QACAE,aAAa;QACbC,MAAM,CAAC,EAAEC,OAAO,EAAEC,IAAI,EAAE;YACtB,qFAAqF;YACrF,OAAOC,IAAAA,sCAAqB,EAACF,SAASN,WAAW,GAAG;gBAAEO;YAAK;QAC7D;IACF;AACF"}
@@ -1,4 +1,4 @@
1
- import { GitCommonOptions, type GetChangesBetweenRefsOptions } from "../git/types";
1
+ import { type GitCommonOptions, type GetChangesBetweenRefsOptions } from "../git/types.js";
2
2
  type GetChangedPackagesOptions = GitCommonOptions & {
3
3
  /** The `merge-base` branch (must have been fetched locally) */
4
4
  target?: string;
@@ -1,52 +1,69 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getChangedPackages = exports.getChangedPackagesBetweenRefs = void 0;
4
- const git_1 = require("../git");
5
- const getPackagesByFiles_1 = require("./getPackagesByFiles");
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: Object.getOwnPropertyDescriptor(all, name).get
9
+ });
10
+ }
11
+ _export(exports, {
12
+ get getChangedPackages () {
13
+ return getChangedPackages;
14
+ },
15
+ get getChangedPackagesBetweenRefs () {
16
+ return getChangedPackagesBetweenRefs;
17
+ }
18
+ });
19
+ const _git = require("../git");
20
+ const _getPackagesByFiles = require("./getPackagesByFiles.js");
6
21
  function getChangedPackagesBetweenRefs(paramsOrCwd, _fromRef, _toRef, _ignoreGlobs, _returnAllPackagesOnNoMatch) {
7
- const params = typeof paramsOrCwd === "string"
8
- ? {
9
- cwd: paramsOrCwd,
10
- fromRef: _fromRef,
11
- toRef: _toRef,
12
- ignoreGlobs: _ignoreGlobs,
13
- returnAllPackagesOnNoMatch: _returnAllPackagesOnNoMatch,
14
- }
15
- : paramsOrCwd;
22
+ var _gitOptions;
23
+ const params = typeof paramsOrCwd === "string" ? {
24
+ cwd: paramsOrCwd,
25
+ fromRef: _fromRef,
26
+ toRef: _toRef,
27
+ ignoreGlobs: _ignoreGlobs,
28
+ returnAllPackagesOnNoMatch: _returnAllPackagesOnNoMatch
29
+ } : paramsOrCwd;
16
30
  const { fromRef, toRef, ignoreGlobs, returnAllPackagesOnNoMatch = true, ...gitOptions } = params;
17
- gitOptions.throwOnError ?? (gitOptions.throwOnError = true);
31
+ (_gitOptions = gitOptions).throwOnError ?? (_gitOptions.throwOnError = true);
18
32
  const changes = [
19
33
  ...new Set([
20
- ...(0, git_1.getUntrackedChanges)(gitOptions),
21
- ...(0, git_1.getUnstagedChanges)(gitOptions),
22
- ...(0, git_1.getChangesBetweenRefs)({ fromRef, toRef, ...gitOptions }),
23
- ...(0, git_1.getStagedChanges)(gitOptions),
24
- ]),
34
+ ...(0, _git.getUntrackedChanges)(gitOptions),
35
+ ...(0, _git.getUnstagedChanges)(gitOptions),
36
+ ...(0, _git.getChangesBetweenRefs)({
37
+ fromRef,
38
+ toRef,
39
+ ...gitOptions
40
+ }),
41
+ ...(0, _git.getStagedChanges)(gitOptions)
42
+ ])
25
43
  ];
26
- return (0, getPackagesByFiles_1.getPackagesByFiles)({
44
+ return (0, _getPackagesByFiles.getPackagesByFiles)({
27
45
  root: gitOptions.cwd,
28
46
  files: changes,
29
47
  ignoreGlobs,
30
- returnAllPackagesOnNoMatch,
48
+ returnAllPackagesOnNoMatch
31
49
  });
32
50
  }
33
- exports.getChangedPackagesBetweenRefs = getChangedPackagesBetweenRefs;
34
51
  function getChangedPackages(cwdOrOptions, target, ignoreGlobs, returnAllPackagesOnNoMatch) {
52
+ var _gitOptions;
35
53
  let gitOptions;
36
54
  if (typeof cwdOrOptions === "string") {
37
- gitOptions = { cwd: cwdOrOptions };
38
- }
39
- else {
55
+ gitOptions = {
56
+ cwd: cwdOrOptions
57
+ };
58
+ } else {
40
59
  ({ target, ignoreGlobs, returnAllPackagesOnNoMatch, ...gitOptions } = cwdOrOptions);
41
60
  }
42
- gitOptions.throwOnError ?? (gitOptions.throwOnError = true);
43
- const targetBranch = target || (0, git_1.getDefaultRemoteBranch)(gitOptions);
61
+ (_gitOptions = gitOptions).throwOnError ?? (_gitOptions.throwOnError = true);
62
+ const targetBranch = target || (0, _git.getDefaultRemoteBranch)(gitOptions);
44
63
  return getChangedPackagesBetweenRefs({
45
64
  fromRef: targetBranch,
46
65
  ...gitOptions,
47
66
  ignoreGlobs,
48
- returnAllPackagesOnNoMatch,
67
+ returnAllPackagesOnNoMatch
49
68
  });
50
69
  }
51
- exports.getChangedPackages = getChangedPackages;
52
- //# sourceMappingURL=getChangedPackages.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getChangedPackages.js","sourceRoot":"","sources":["../../src/workspaces/getChangedPackages.ts"],"names":[],"mappings":";;;AAAA,gCAMgB;AAEhB,6DAA0D;AAiD1D,SAAgB,6BAA6B,CAC3C,WAA0D,EAC1D,QAAiB,EACjB,MAAe,EACf,YAAuB,EACvB,2BAAqC;IAErC,MAAM,MAAM,GACV,OAAO,WAAW,KAAK,QAAQ;QAC7B,CAAC,CAAC;YACE,GAAG,EAAE,WAAW;YAChB,OAAO,EAAE,QAAS;YAClB,KAAK,EAAE,MAAM;YACb,WAAW,EAAE,YAAY;YACzB,0BAA0B,EAAE,2BAA2B;SACxD;QACH,CAAC,CAAC,WAAW,CAAC;IAClB,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,0BAA0B,GAAG,IAAI,EAAE,GAAG,UAAU,EAAE,GAAG,MAAM,CAAC;IACjG,UAAU,CAAC,YAAY,KAAvB,UAAU,CAAC,YAAY,GAAK,IAAI,EAAC;IAEjC,MAAM,OAAO,GAAG;QACd,GAAG,IAAI,GAAG,CAAC;YACT,GAAG,IAAA,yBAAmB,EAAC,UAAU,CAAC;YAClC,GAAG,IAAA,wBAAkB,EAAC,UAAU,CAAC;YACjC,GAAG,IAAA,2BAAqB,EAAC,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,UAAU,EAAE,CAAC;YAC3D,GAAG,IAAA,sBAAgB,EAAC,UAAU,CAAC;SAChC,CAAC;KACH,CAAC;IAEF,OAAO,IAAA,uCAAkB,EAAC;QACxB,IAAI,EAAE,UAAU,CAAC,GAAG;QACpB,KAAK,EAAE,OAAO;QACd,WAAW;QACX,0BAA0B;KAC3B,CAAC,CAAC;AACL,CAAC;AAnCD,sEAmCC;AAoCD,SAAgB,kBAAkB,CAChC,YAAgD,EAChD,MAAe,EACf,WAAsB,EACtB,0BAAoC;IAEpC,IAAI,UAA4B,CAAC;IACjC,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE;QACpC,UAAU,GAAG,EAAE,GAAG,EAAE,YAAY,EAAE,CAAC;KACpC;SAAM;QACL,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,0BAA0B,EAAE,GAAG,UAAU,EAAE,GAAG,YAAY,CAAC,CAAC;KACrF;IACD,UAAU,CAAC,YAAY,KAAvB,UAAU,CAAC,YAAY,GAAK,IAAI,EAAC;IAEjC,MAAM,YAAY,GAAG,MAAM,IAAI,IAAA,4BAAsB,EAAC,UAAU,CAAC,CAAC;IAElE,OAAO,6BAA6B,CAAC;QACnC,OAAO,EAAE,YAAY;QACrB,GAAG,UAAU;QACb,WAAW;QACX,0BAA0B;KAC3B,CAAC,CAAC;AACL,CAAC;AAtBD,gDAsBC"}
1
+ {"version":3,"sources":["../../src/workspaces/getChangedPackages.ts"],"sourcesContent":["import {\n getChangesBetweenRefs,\n getDefaultRemoteBranch,\n getStagedChanges,\n getUnstagedChanges,\n getUntrackedChanges,\n} from \"../git\";\nimport { type GitCommonOptions, type GetChangesBetweenRefsOptions } from \"../git/types.js\";\nimport { getPackagesByFiles } from \"./getPackagesByFiles.js\";\n\ntype GetChangedPackagesOptions = GitCommonOptions & {\n /** The `merge-base` branch (must have been fetched locally) */\n target?: string;\n /** Glob patterns to ignore */\n ignoreGlobs?: string[];\n /** If true (the default), return all packages if no matches are found for any file. */\n returnAllPackagesOnNoMatch?: boolean;\n};\n\ntype GetChangedPackagesBetweenRefsOptions = Omit<GetChangedPackagesOptions, \"target\"> &\n Pick<GetChangesBetweenRefsOptions, \"fromRef\" | \"toRef\">;\n\n/**\n * Finds all packages that had been changed between two refs in the repo under cwd,\n * by executing `git diff $fromRef...$toRef`.\n *\n * **NOTE: The new object params version will throw if any of the git operations error.**\n * Disabling this behavior is not recommended due to the potential for hiding other issues,\n * but can be done by setting `throwOnError: false` in the options.\n *\n * Note that by default, if a repo-wide file such as the root package.json has changed,\n * all packages are assumed to have changed. (This is highly lage-specific behavior.)\n * Disable by setting `returnAllPackagesOnNoMatch` to `false`.\n *\n * Explanation of the three dots:\n *\n * ```txt\n * git diff [--options] <commit>...<commit> [--] [<path>...]\n *\n * This form is to view the changes on the branch containing and up to\n * the second <commit>, starting at a common ancestor of both\n * <commit>. \"git diff A...B\" is equivalent to \"git diff\n * $(git-merge-base A B) B\". You can omit any one of <commit>, which\n * has the same effect as using HEAD instead.\n * ```\n *\n * @returns list of package names that have changed\n */\nexport function getChangedPackagesBetweenRefs(params: GetChangedPackagesBetweenRefsOptions): string[];\n/** @deprecated Use object params version */\nexport function getChangedPackagesBetweenRefs(\n cwd: string,\n fromRef: string,\n toRef?: string,\n ignoreGlobs?: string[],\n returnAllPackagesOnNoMatch?: boolean\n): string[];\nexport function getChangedPackagesBetweenRefs(\n paramsOrCwd: GetChangedPackagesBetweenRefsOptions | string,\n _fromRef?: string,\n _toRef?: string,\n _ignoreGlobs?: string[],\n _returnAllPackagesOnNoMatch?: boolean\n): string[] {\n const params: GetChangedPackagesBetweenRefsOptions =\n typeof paramsOrCwd === \"string\"\n ? {\n cwd: paramsOrCwd,\n fromRef: _fromRef!,\n toRef: _toRef,\n ignoreGlobs: _ignoreGlobs,\n returnAllPackagesOnNoMatch: _returnAllPackagesOnNoMatch,\n }\n : paramsOrCwd;\n const { fromRef, toRef, ignoreGlobs, returnAllPackagesOnNoMatch = true, ...gitOptions } = params;\n gitOptions.throwOnError ??= true;\n\n const changes = [\n ...new Set([\n ...getUntrackedChanges(gitOptions),\n ...getUnstagedChanges(gitOptions),\n ...getChangesBetweenRefs({ fromRef, toRef, ...gitOptions }),\n ...getStagedChanges(gitOptions),\n ]),\n ];\n\n return getPackagesByFiles({\n root: gitOptions.cwd,\n files: changes,\n ignoreGlobs,\n returnAllPackagesOnNoMatch,\n });\n}\n\n/**\n * Finds all packages that had been changed in the repo under cwd, by executing\n * `git diff $target...`.\n *\n * **NOTE: The new object params version will throw if any of the git operations error.**\n * Disabling this behavior is not recommended due to the potential for hiding other issues,\n * but can be done by setting `throwOnError: false` in the options.\n *\n * Note that by default, if a repo-wide file such as the root package.json has changed,\n * all packages are assumed to have changed. (This is highly lage-specific behavior.)\n * Disable by setting `returnAllPackagesOnNoMatch` to `false`.\n *\n * Explanation of the three dots:\n *\n * ```txt\n * git diff [--options] <commit>...<commit> [--] [<path>...]\n *\n * This form is to view the changes on the branch containing and up to\n * the second <commit>, starting at a common ancestor of both\n * <commit>. \"git diff A...B\" is equivalent to \"git diff\n * $(git-merge-base A B) B\". You can omit any one of <commit>, which\n * has the same effect as using HEAD instead.\n * ```\n *\n * @returns list of package names that have changed\n */\nexport function getChangedPackages(params: GetChangedPackagesOptions): string[];\n/** @deprecated Use object params version */\nexport function getChangedPackages(\n cwd: string,\n target?: string,\n ignoreGlobs?: string[],\n returnAllPackagesOnNoMatch?: boolean\n): string[];\nexport function getChangedPackages(\n cwdOrOptions: string | GetChangedPackagesOptions,\n target?: string,\n ignoreGlobs?: string[],\n returnAllPackagesOnNoMatch?: boolean\n): string[] {\n let gitOptions: GitCommonOptions;\n if (typeof cwdOrOptions === \"string\") {\n gitOptions = { cwd: cwdOrOptions };\n } else {\n ({ target, ignoreGlobs, returnAllPackagesOnNoMatch, ...gitOptions } = cwdOrOptions);\n }\n gitOptions.throwOnError ??= true;\n\n const targetBranch = target || getDefaultRemoteBranch(gitOptions);\n\n return getChangedPackagesBetweenRefs({\n fromRef: targetBranch,\n ...gitOptions,\n ignoreGlobs,\n returnAllPackagesOnNoMatch,\n });\n}\n"],"names":["getChangedPackages","getChangedPackagesBetweenRefs","paramsOrCwd","_fromRef","_toRef","_ignoreGlobs","_returnAllPackagesOnNoMatch","gitOptions","params","cwd","fromRef","toRef","ignoreGlobs","returnAllPackagesOnNoMatch","throwOnError","changes","Set","getUntrackedChanges","getUnstagedChanges","getChangesBetweenRefs","getStagedChanges","getPackagesByFiles","root","files","cwdOrOptions","target","targetBranch","getDefaultRemoteBranch"],"mappings":";;;;;;;;;;;QAgIgBA;eAAAA;;QAvEAC;eAAAA;;;qBAnDT;oCAE4B;AAiD5B,SAASA,8BACdC,WAA0D,EAC1DC,QAAiB,EACjBC,MAAe,EACfC,YAAuB,EACvBC,2BAAqC;QAarCC;IAXA,MAAMC,SACJ,OAAON,gBAAgB,WACnB;QACEO,KAAKP;QACLQ,SAASP;QACTQ,OAAOP;QACPQ,aAAaP;QACbQ,4BAA4BP;IAC9B,IACAJ;IACN,MAAM,EAAEQ,OAAO,EAAEC,KAAK,EAAEC,WAAW,EAAEC,6BAA6B,IAAI,EAAE,GAAGN,YAAY,GAAGC;IAC1FD,CAAAA,cAAAA,YAAWO,YAAY,KAAvBP,YAAWO,YAAY,GAAK;IAE5B,MAAMC,UAAU;WACX,IAAIC,IAAI;eACNC,IAAAA,wBAAmB,EAACV;eACpBW,IAAAA,uBAAkB,EAACX;eACnBY,IAAAA,0BAAqB,EAAC;gBAAET;gBAASC;gBAAO,GAAGJ,UAAU;YAAC;eACtDa,IAAAA,qBAAgB,EAACb;SACrB;KACF;IAED,OAAOc,IAAAA,sCAAkB,EAAC;QACxBC,MAAMf,WAAWE,GAAG;QACpBc,OAAOR;QACPH;QACAC;IACF;AACF;AAoCO,SAASb,mBACdwB,YAAgD,EAChDC,MAAe,EACfb,WAAsB,EACtBC,0BAAoC;QAQpCN;IANA,IAAIA;IACJ,IAAI,OAAOiB,iBAAiB,UAAU;QACpCjB,aAAa;YAAEE,KAAKe;QAAa;IACnC,OAAO;QACJ,CAAA,EAAEC,MAAM,EAAEb,WAAW,EAAEC,0BAA0B,EAAE,GAAGN,YAAY,GAAGiB,YAAW;IACnF;IACAjB,CAAAA,cAAAA,YAAWO,YAAY,KAAvBP,YAAWO,YAAY,GAAK;IAE5B,MAAMY,eAAeD,UAAUE,IAAAA,2BAAsB,EAACpB;IAEtD,OAAON,8BAA8B;QACnCS,SAASgB;QACT,GAAGnB,UAAU;QACbK;QACAC;IACF;AACF"}
@@ -1,38 +1,43 @@
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.getPackagesByFiles = void 0;
7
- const micromatch_1 = __importDefault(require("micromatch"));
8
- const path_1 = __importDefault(require("path"));
9
- const getWorkspaces_1 = require("./getWorkspaces");
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "getPackagesByFiles", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return getPackagesByFiles;
9
+ }
10
+ });
11
+ const _micromatch = /*#__PURE__*/ _interop_require_default(require("micromatch"));
12
+ const _path = /*#__PURE__*/ _interop_require_default(require("path"));
13
+ const _getWorkspaceInfos = require("./getWorkspaceInfos.js");
14
+ function _interop_require_default(obj) {
15
+ return obj && obj.__esModule ? obj : {
16
+ default: obj
17
+ };
18
+ }
10
19
  function getPackagesByFiles(cwdOrOptions, files, ignoreGlobs, returnAllPackagesOnNoMatch) {
11
20
  let root;
12
21
  if (typeof cwdOrOptions === "string") {
13
22
  root = cwdOrOptions;
14
23
  files = files;
15
- }
16
- else {
24
+ } else {
17
25
  ({ root, files, ignoreGlobs, returnAllPackagesOnNoMatch } = cwdOrOptions);
18
26
  }
19
- const workspaces = (0, getWorkspaces_1.getWorkspaces)(root);
20
- const ignoreSet = new Set(ignoreGlobs?.length ? (0, micromatch_1.default)(files, ignoreGlobs) : []);
21
- const filteredFiles = files.filter((change) => !ignoreSet.has(change));
27
+ const workspaces = (0, _getWorkspaceInfos.getWorkspaceInfos)(root) || [];
28
+ const ignoreSet = new Set(ignoreGlobs?.length ? (0, _micromatch.default)(files, ignoreGlobs) : []);
29
+ const filteredFiles = files.filter((change)=>!ignoreSet.has(change));
22
30
  const packages = new Set();
23
- for (const file of filteredFiles) {
24
- const candidates = workspaces.filter((pkg) => file.startsWith(path_1.default.relative(root, pkg.path).replace(/\\/g, "/")));
31
+ for (const file of filteredFiles){
32
+ const candidates = workspaces.filter((pkg)=>file.startsWith(_path.default.relative(root, pkg.path).replace(/\\/g, "/")));
25
33
  if (candidates.length) {
26
- const found = candidates.reduce((found, item) => {
27
- return found.path.length > item.path.length ? found : item;
28
- }, candidates[0]);
34
+ const found = candidates.reduce((fnd, item)=>fnd.path.length > item.path.length ? fnd : item, candidates[0]);
29
35
  packages.add(found.name);
30
- }
31
- else if (returnAllPackagesOnNoMatch) {
32
- return workspaces.map((pkg) => pkg.name);
36
+ } else if (returnAllPackagesOnNoMatch) {
37
+ return workspaces.map((pkg)=>pkg.name);
33
38
  }
34
39
  }
35
- return [...packages];
40
+ return [
41
+ ...packages
42
+ ];
36
43
  }
37
- exports.getPackagesByFiles = getPackagesByFiles;
38
- //# sourceMappingURL=getPackagesByFiles.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getPackagesByFiles.js","sourceRoot":"","sources":["../../src/workspaces/getPackagesByFiles.ts"],"names":[],"mappings":";;;;;;AAAA,4DAAoC;AACpC,gDAAwB;AACxB,mDAAgD;AA0BhD,SAAgB,kBAAkB,CAChC,YAAgD,EAChD,KAAgB,EAChB,WAAsB,EACtB,0BAAoC;IAEpC,IAAI,IAAY,CAAC;IACjB,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE;QACpC,IAAI,GAAG,YAAY,CAAC;QACpB,KAAK,GAAG,KAAM,CAAC;KAChB;SAAM;QACL,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE,0BAA0B,EAAE,GAAG,YAAY,CAAC,CAAC;KAC3E;IAED,MAAM,UAAU,GAAG,IAAA,6BAAa,EAAC,IAAI,CAAC,CAAC;IACvC,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC,IAAA,oBAAU,EAAC,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAErF,MAAM,aAAa,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;IAEvE,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAU,CAAC;IAEnC,KAAK,MAAM,IAAI,IAAI,aAAa,EAAE;QAChC,MAAM,UAAU,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,cAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;QAElH,IAAI,UAAU,CAAC,MAAM,EAAE;YACrB,MAAM,KAAK,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;gBAC9C,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;YAC7D,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;YAClB,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;SAC1B;aAAM,IAAI,0BAA0B,EAAE;YACrC,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;SAC1C;KACF;IAED,OAAO,CAAC,GAAG,QAAQ,CAAC,CAAC;AACvB,CAAC;AAnCD,gDAmCC"}
1
+ {"version":3,"sources":["../../src/workspaces/getPackagesByFiles.ts"],"sourcesContent":["import micromatch from \"micromatch\";\nimport path from \"path\";\nimport { getWorkspaceInfos } from \"./getWorkspaceInfos.js\";\n\ninterface GetPackagesByFilesOptions {\n /** Monorepo root directory */\n root: string;\n /** Files to search for */\n files: string[];\n /** Glob patterns to ignore */\n ignoreGlobs?: string[];\n /** If true, will return all packages if no matches are found for any file */\n returnAllPackagesOnNoMatch?: boolean;\n}\n\n/**\n * Given a list of files, finds all packages names that contain those files\n *\n * @returns Package names that have changed\n */\nexport function getPackagesByFiles(options: GetPackagesByFilesOptions): string[];\n/** @deprecated Use object parameter signature instead */\nexport function getPackagesByFiles(\n root: string,\n files: string[],\n ignoreGlobs?: string[],\n returnAllPackagesOnNoMatch?: boolean\n): string[];\nexport function getPackagesByFiles(\n cwdOrOptions: string | GetPackagesByFilesOptions,\n files?: string[],\n ignoreGlobs?: string[],\n returnAllPackagesOnNoMatch?: boolean\n): string[] {\n let root: string;\n if (typeof cwdOrOptions === \"string\") {\n root = cwdOrOptions;\n files = files!;\n } else {\n ({ root, files, ignoreGlobs, returnAllPackagesOnNoMatch } = cwdOrOptions);\n }\n\n const workspaces = getWorkspaceInfos(root) || [];\n const ignoreSet = new Set(ignoreGlobs?.length ? micromatch(files, ignoreGlobs) : []);\n\n const filteredFiles = files.filter((change) => !ignoreSet.has(change));\n\n const packages = new Set<string>();\n\n for (const file of filteredFiles) {\n const candidates = workspaces.filter((pkg) => file.startsWith(path.relative(root, pkg.path).replace(/\\\\/g, \"/\")));\n\n if (candidates.length) {\n const found = candidates.reduce((fnd, item) => (fnd.path.length > item.path.length ? fnd : item), candidates[0]);\n packages.add(found.name);\n } else if (returnAllPackagesOnNoMatch) {\n return workspaces.map((pkg) => pkg.name);\n }\n }\n\n return [...packages];\n}\n"],"names":["getPackagesByFiles","cwdOrOptions","files","ignoreGlobs","returnAllPackagesOnNoMatch","root","workspaces","getWorkspaceInfos","ignoreSet","Set","length","micromatch","filteredFiles","filter","change","has","packages","file","candidates","pkg","startsWith","path","relative","replace","found","reduce","fnd","item","add","name","map"],"mappings":";;;;+BA4BgBA;;;eAAAA;;;mEA5BO;6DACN;mCACiB;;;;;;AA0B3B,SAASA,mBACdC,YAAgD,EAChDC,KAAgB,EAChBC,WAAsB,EACtBC,0BAAoC;IAEpC,IAAIC;IACJ,IAAI,OAAOJ,iBAAiB,UAAU;QACpCI,OAAOJ;QACPC,QAAQA;IACV,OAAO;QACJ,CAAA,EAAEG,IAAI,EAAEH,KAAK,EAAEC,WAAW,EAAEC,0BAA0B,EAAE,GAAGH,YAAW;IACzE;IAEA,MAAMK,aAAaC,IAAAA,oCAAiB,EAACF,SAAS,EAAE;IAChD,MAAMG,YAAY,IAAIC,IAAIN,aAAaO,SAASC,IAAAA,mBAAU,EAACT,OAAOC,eAAe,EAAE;IAEnF,MAAMS,gBAAgBV,MAAMW,MAAM,CAAC,CAACC,SAAW,CAACN,UAAUO,GAAG,CAACD;IAE9D,MAAME,WAAW,IAAIP;IAErB,KAAK,MAAMQ,QAAQL,cAAe;QAChC,MAAMM,aAAaZ,WAAWO,MAAM,CAAC,CAACM,MAAQF,KAAKG,UAAU,CAACC,aAAI,CAACC,QAAQ,CAACjB,MAAMc,IAAIE,IAAI,EAAEE,OAAO,CAAC,OAAO;QAE3G,IAAIL,WAAWR,MAAM,EAAE;YACrB,MAAMc,QAAQN,WAAWO,MAAM,CAAC,CAACC,KAAKC,OAAUD,IAAIL,IAAI,CAACX,MAAM,GAAGiB,KAAKN,IAAI,CAACX,MAAM,GAAGgB,MAAMC,MAAOT,UAAU,CAAC,EAAE;YAC/GF,SAASY,GAAG,CAACJ,MAAMK,IAAI;QACzB,OAAO,IAAIzB,4BAA4B;YACrC,OAAOE,WAAWwB,GAAG,CAAC,CAACX,MAAQA,IAAIU,IAAI;QACzC;IACF;IAEA,OAAO;WAAIb;KAAS;AACtB"}
@@ -0,0 +1,36 @@
1
+ import type { WorkspaceInfos } from "../types/WorkspaceInfo.js";
2
+ import type { WorkspaceManager } from "../types/WorkspaceManager.js";
3
+ /**
4
+ * Get an array with names, paths, and package.json contents for each package ("workspace" in
5
+ * npm/yarn/pnpm terms) within a monorepo. The list of included packages is based on the
6
+ * workspace/monorepo manager's config file.
7
+ *
8
+ * Notes:
9
+ * - The workspace manager, root, and list of package paths for `cwd` are cached internally,
10
+ * but the package contents are not.
11
+ * - To get an object with package names as keys, use `getPackageInfos` instead.
12
+ *
13
+ * @param managerOverride Workspace/monorepo manager to use instead of auto-detecting
14
+ *
15
+ * @returns Array of workspace package infos, or undefined if not found (not a monorepo)
16
+ * or there's any issue. (Logs verbose warnings instead of throwing on error.)
17
+ */
18
+ export declare function getWorkspaceInfos(cwd: string, managerOverride?: WorkspaceManager): WorkspaceInfos | undefined;
19
+ /**
20
+ * Get an array with names, paths, and package.json contents for each package ("workspace" in
21
+ * npm/yarn/pnpm terms) within a monorepo. The list of included packages is based on the
22
+ * workspace/monorepo manager's config file.
23
+ *
24
+ * Notes:
25
+ * - **WARNING**: As of writing, this will start promises to read all package.json files in
26
+ * parallel, without direct concurrency control.
27
+ * - The workspace manager, root, and list of package paths for `cwd` are cached internally,
28
+ * but the package contents are not.
29
+ * - To get an object with package names as keys, use `getPackageInfosAsync` instead.
30
+ *
31
+ * @param managerOverride Workspace/monorepo manager to use instead of auto-detecting
32
+ *
33
+ * @returns Array of workspace package infos, or undefined if not found (not a monorepo)
34
+ * or there's any issue. (Logs verbose warnings instead of throwing on error.)
35
+ */
36
+ export declare function getWorkspaceInfosAsync(cwd: string, managerOverride?: WorkspaceManager): Promise<WorkspaceInfos | undefined>;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: Object.getOwnPropertyDescriptor(all, name).get
9
+ });
10
+ }
11
+ _export(exports, {
12
+ get getWorkspaceInfos () {
13
+ return getWorkspaceInfos;
14
+ },
15
+ get getWorkspaceInfosAsync () {
16
+ return getWorkspaceInfosAsync;
17
+ }
18
+ });
19
+ const _getPackageInfo = require("../getPackageInfo.js");
20
+ const _getWorkspacePackagePaths = require("./getWorkspacePackagePaths.js");
21
+ const _wrapWorkspaceUtility = require("./wrapWorkspaceUtility.js");
22
+ function getWorkspaceInfos(cwd, managerOverride) {
23
+ return (0, _wrapWorkspaceUtility.wrapWorkspaceUtility)({
24
+ cwd,
25
+ managerOverride,
26
+ description: "workspace package infos",
27
+ impl: ({ manager })=>{
28
+ return (0, _getWorkspacePackagePaths.getWorkspacePackagePaths)(cwd, manager)?.map((packagePath)=>{
29
+ // getPackageInfo logs a warning if it can't be read
30
+ const packageJson = (0, _getPackageInfo.getPackageInfo)(packagePath);
31
+ return packageJson && {
32
+ name: packageJson.name,
33
+ path: packagePath,
34
+ packageJson
35
+ };
36
+ }).filter(Boolean);
37
+ }
38
+ });
39
+ }
40
+ async function getWorkspaceInfosAsync(cwd, managerOverride) {
41
+ return (0, _wrapWorkspaceUtility.wrapAsyncWorkspaceUtility)({
42
+ cwd,
43
+ managerOverride,
44
+ description: "workspace package infos",
45
+ impl: async ({ manager })=>{
46
+ const packagePaths = await (0, _getWorkspacePackagePaths.getWorkspacePackagePathsAsync)(cwd, manager);
47
+ if (!packagePaths) return undefined;
48
+ const workspacePkgPromises = packagePaths.map(async (packagePath)=>{
49
+ // getPackageInfoAsync logs a warning if it can't be read
50
+ const packageJson = await (0, _getPackageInfo.getPackageInfoAsync)(packagePath);
51
+ return packageJson && {
52
+ name: packageJson.name,
53
+ path: packagePath,
54
+ packageJson
55
+ };
56
+ });
57
+ return (await Promise.all(workspacePkgPromises)).filter(Boolean);
58
+ }
59
+ });
60
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/workspaces/getWorkspaceInfos.ts"],"sourcesContent":["import { getPackageInfo, getPackageInfoAsync } from \"../getPackageInfo.js\";\nimport type { WorkspaceInfos, WorkspacePackageInfo } from \"../types/WorkspaceInfo.js\";\nimport type { WorkspaceManager } from \"../types/WorkspaceManager.js\";\nimport { getWorkspacePackagePaths, getWorkspacePackagePathsAsync } from \"./getWorkspacePackagePaths.js\";\nimport { wrapAsyncWorkspaceUtility, wrapWorkspaceUtility } from \"./wrapWorkspaceUtility.js\";\n\n/**\n * Get an array with names, paths, and package.json contents for each package (\"workspace\" in\n * npm/yarn/pnpm terms) within a monorepo. The list of included packages is based on the\n * workspace/monorepo manager's config file.\n *\n * Notes:\n * - The workspace manager, root, and list of package paths for `cwd` are cached internally,\n * but the package contents are not.\n * - To get an object with package names as keys, use `getPackageInfos` instead.\n *\n * @param managerOverride Workspace/monorepo manager to use instead of auto-detecting\n *\n * @returns Array of workspace package infos, or undefined if not found (not a monorepo)\n * or there's any issue. (Logs verbose warnings instead of throwing on error.)\n */\nexport function getWorkspaceInfos(cwd: string, managerOverride?: WorkspaceManager): WorkspaceInfos | undefined {\n return wrapWorkspaceUtility({\n cwd,\n managerOverride,\n description: \"workspace package infos\",\n impl: ({ manager }) => {\n return getWorkspacePackagePaths(cwd, manager)\n ?.map<WorkspacePackageInfo | undefined>((packagePath) => {\n // getPackageInfo logs a warning if it can't be read\n const packageJson = getPackageInfo(packagePath);\n return packageJson && { name: packageJson.name, path: packagePath, packageJson };\n })\n .filter(Boolean) as WorkspaceInfos | undefined;\n },\n });\n}\n\n/**\n * Get an array with names, paths, and package.json contents for each package (\"workspace\" in\n * npm/yarn/pnpm terms) within a monorepo. The list of included packages is based on the\n * workspace/monorepo manager's config file.\n *\n * Notes:\n * - **WARNING**: As of writing, this will start promises to read all package.json files in\n * parallel, without direct concurrency control.\n * - The workspace manager, root, and list of package paths for `cwd` are cached internally,\n * but the package contents are not.\n * - To get an object with package names as keys, use `getPackageInfosAsync` instead.\n *\n * @param managerOverride Workspace/monorepo manager to use instead of auto-detecting\n *\n * @returns Array of workspace package infos, or undefined if not found (not a monorepo)\n * or there's any issue. (Logs verbose warnings instead of throwing on error.)\n */\nexport async function getWorkspaceInfosAsync(\n cwd: string,\n managerOverride?: WorkspaceManager\n): Promise<WorkspaceInfos | undefined> {\n return wrapAsyncWorkspaceUtility({\n cwd,\n managerOverride,\n description: \"workspace package infos\",\n impl: async ({ manager }) => {\n const packagePaths = await getWorkspacePackagePathsAsync(cwd, manager);\n if (!packagePaths) return undefined;\n\n const workspacePkgPromises = packagePaths.map<Promise<WorkspacePackageInfo | undefined>>(async (packagePath) => {\n // getPackageInfoAsync logs a warning if it can't be read\n const packageJson = await getPackageInfoAsync(packagePath);\n return packageJson && { name: packageJson.name, path: packagePath, packageJson };\n });\n\n return (await Promise.all(workspacePkgPromises)).filter(Boolean) as WorkspaceInfos;\n },\n });\n}\n"],"names":["getWorkspaceInfos","getWorkspaceInfosAsync","cwd","managerOverride","wrapWorkspaceUtility","description","impl","manager","getWorkspacePackagePaths","map","packagePath","packageJson","getPackageInfo","name","path","filter","Boolean","wrapAsyncWorkspaceUtility","packagePaths","getWorkspacePackagePathsAsync","undefined","workspacePkgPromises","getPackageInfoAsync","Promise","all"],"mappings":";;;;;;;;;;;QAqBgBA;eAAAA;;QAkCMC;eAAAA;;;gCAvD8B;0CAGoB;sCACR;AAiBzD,SAASD,kBAAkBE,GAAW,EAAEC,eAAkC;IAC/E,OAAOC,IAAAA,0CAAoB,EAAC;QAC1BF;QACAC;QACAE,aAAa;QACbC,MAAM,CAAC,EAAEC,OAAO,EAAE;YAChB,OAAOC,IAAAA,kDAAwB,EAACN,KAAKK,UACjCE,IAAsC,CAACC;gBACvC,oDAAoD;gBACpD,MAAMC,cAAcC,IAAAA,8BAAc,EAACF;gBACnC,OAAOC,eAAe;oBAAEE,MAAMF,YAAYE,IAAI;oBAAEC,MAAMJ;oBAAaC;gBAAY;YACjF,GACCI,OAAOC;QACZ;IACF;AACF;AAmBO,eAAef,uBACpBC,GAAW,EACXC,eAAkC;IAElC,OAAOc,IAAAA,+CAAyB,EAAC;QAC/Bf;QACAC;QACAE,aAAa;QACbC,MAAM,OAAO,EAAEC,OAAO,EAAE;YACtB,MAAMW,eAAe,MAAMC,IAAAA,uDAA6B,EAACjB,KAAKK;YAC9D,IAAI,CAACW,cAAc,OAAOE;YAE1B,MAAMC,uBAAuBH,aAAaT,GAAG,CAA4C,OAAOC;gBAC9F,yDAAyD;gBACzD,MAAMC,cAAc,MAAMW,IAAAA,mCAAmB,EAACZ;gBAC9C,OAAOC,eAAe;oBAAEE,MAAMF,YAAYE,IAAI;oBAAEC,MAAMJ;oBAAaC;gBAAY;YACjF;YAEA,OAAO,AAAC,CAAA,MAAMY,QAAQC,GAAG,CAACH,qBAAoB,EAAGN,MAAM,CAACC;QAC1D;IACF;AACF"}
@@ -0,0 +1,16 @@
1
+ import type { WorkspaceManager } from "../types/WorkspaceManager.js";
2
+ /**
3
+ * Get the root directory of a monorepo, defined as the directory where the workspace/monorepo manager
4
+ * config file is located. (Does not rely in any way on git, and the result is cached by `cwd`.)
5
+ *
6
+ * @param cwd Start searching from here
7
+ * @param managerOverride Search for only this manager's config file
8
+ *
9
+ * @returns Workspace manager root directory. Returns undefined (and verbose logs) on error or if
10
+ * not found, unless `throwOnError` is set.
11
+ */
12
+ export declare function getWorkspaceManagerRoot(cwd: string, managerOverride?: WorkspaceManager): string | undefined;
13
+ export declare function getWorkspaceManagerRoot(cwd: string, managerOverride: WorkspaceManager | undefined, options?: {
14
+ /** Throw if there's an error or if the root is not found */
15
+ throwOnError: true;
16
+ }): string;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "getWorkspaceManagerRoot", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return getWorkspaceManagerRoot;
9
+ }
10
+ });
11
+ const _logging = require("../logging.js");
12
+ const _implementations = require("./implementations");
13
+ function getWorkspaceManagerRoot(cwd, managerOverride, options) {
14
+ const logOrThrow = (message)=>{
15
+ if (options?.throwOnError) {
16
+ throw new Error(message);
17
+ } else {
18
+ (0, _logging.logVerboseWarning)(message);
19
+ }
20
+ };
21
+ let root;
22
+ try {
23
+ root = (0, _implementations.getWorkspaceManagerAndRoot)(cwd, undefined, managerOverride)?.root;
24
+ } catch (err) {
25
+ logOrThrow(`Error getting ${managerOverride || "workspace/monorepo manager"} root from ${cwd}: ${err}`);
26
+ return;
27
+ }
28
+ if (!root) {
29
+ logOrThrow(`Could not find ${managerOverride || "workspace/monorepo manager"} root from ${cwd}`);
30
+ }
31
+ return root;
32
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/workspaces/getWorkspaceManagerRoot.ts"],"sourcesContent":["import { logVerboseWarning } from \"../logging.js\";\nimport { getWorkspaceManagerAndRoot } from \"./implementations\";\nimport type { WorkspaceManager } from \"../types/WorkspaceManager.js\";\n\n/**\n * Get the root directory of a monorepo, defined as the directory where the workspace/monorepo manager\n * config file is located. (Does not rely in any way on git, and the result is cached by `cwd`.)\n *\n * @param cwd Start searching from here\n * @param managerOverride Search for only this manager's config file\n *\n * @returns Workspace manager root directory. Returns undefined (and verbose logs) on error or if\n * not found, unless `throwOnError` is set.\n */\nexport function getWorkspaceManagerRoot(cwd: string, managerOverride?: WorkspaceManager): string | undefined;\nexport function getWorkspaceManagerRoot(\n cwd: string,\n managerOverride: WorkspaceManager | undefined,\n options?: {\n /** Throw if there's an error or if the root is not found */\n throwOnError: true;\n }\n): string;\nexport function getWorkspaceManagerRoot(\n cwd: string,\n managerOverride?: WorkspaceManager,\n options?: { throwOnError: true }\n): string | undefined {\n const logOrThrow = (message: string) => {\n if (options?.throwOnError) {\n throw new Error(message);\n } else {\n logVerboseWarning(message);\n }\n };\n\n let root: string | undefined;\n try {\n root = getWorkspaceManagerAndRoot(cwd, undefined, managerOverride)?.root;\n } catch (err) {\n logOrThrow(`Error getting ${managerOverride || \"workspace/monorepo manager\"} root from ${cwd}: ${err}`);\n return;\n }\n\n if (!root) {\n logOrThrow(`Could not find ${managerOverride || \"workspace/monorepo manager\"} root from ${cwd}`);\n }\n return root;\n}\n"],"names":["getWorkspaceManagerRoot","cwd","managerOverride","options","logOrThrow","message","throwOnError","Error","logVerboseWarning","root","getWorkspaceManagerAndRoot","undefined","err"],"mappings":";;;;+BAuBgBA;;;eAAAA;;;yBAvBkB;iCACS;AAsBpC,SAASA,wBACdC,GAAW,EACXC,eAAkC,EAClCC,OAAgC;IAEhC,MAAMC,aAAa,CAACC;QAClB,IAAIF,SAASG,cAAc;YACzB,MAAM,IAAIC,MAAMF;QAClB,OAAO;YACLG,IAAAA,0BAAiB,EAACH;QACpB;IACF;IAEA,IAAII;IACJ,IAAI;QACFA,OAAOC,IAAAA,2CAA0B,EAACT,KAAKU,WAAWT,kBAAkBO;IACtE,EAAE,OAAOG,KAAK;QACZR,WAAW,CAAC,cAAc,EAAEF,mBAAmB,6BAA6B,WAAW,EAAED,IAAI,EAAE,EAAEW,KAAK;QACtG;IACF;IAEA,IAAI,CAACH,MAAM;QACTL,WAAW,CAAC,eAAe,EAAEF,mBAAmB,6BAA6B,WAAW,EAAED,KAAK;IACjG;IACA,OAAOQ;AACT"}
@@ -1,10 +1,25 @@
1
+ import type { WorkspaceManager } from "../types/WorkspaceManager.js";
1
2
  /**
2
3
  * Get a list of package folder paths in the monorepo. The list of included packages is based on
3
4
  * the manager's config file and matching package folders (which must contain package.json) on disk.
5
+ *
6
+ * (The list of package paths is cached per monorepo root if caching is enabled.)
7
+ *
8
+ * @param managerOverride Workspace/monorepo manager to use instead of auto-detecting
9
+ *
10
+ * @returns Package paths, or undefined if there's any issue
11
+ * (logs verbose warnings instead of throwing on error)
4
12
  */
5
- export declare function getWorkspacePackagePaths(cwd: string): string[];
13
+ export declare function getWorkspacePackagePaths(cwd: string, managerOverride?: WorkspaceManager): string[] | undefined;
6
14
  /**
7
15
  * Get a list of package folder paths in the monorepo. The list of included packages is based on
8
16
  * the manager's config file and matching package folders (which must contain package.json) on disk.
17
+ *
18
+ * (The list of package paths is cached per monorepo root if caching is enabled.)
19
+ *
20
+ * @param managerOverride Workspace/monorepo manager to use instead of auto-detecting
21
+ *
22
+ * @returns Package paths, or undefined if there's any issue
23
+ * (logs verbose warnings instead of throwing on error)
9
24
  */
10
- export declare function getWorkspacePackagePathsAsync(cwd: string): Promise<string[]>;
25
+ export declare function getWorkspacePackagePathsAsync(cwd: string, managerOverride?: WorkspaceManager): Promise<string[] | undefined>;
@@ -1,30 +1,144 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getWorkspacePackagePathsAsync = exports.getWorkspacePackagePaths = void 0;
4
- const implementations_1 = require("./implementations");
5
- /**
6
- * Get a list of package folder paths in the monorepo. The list of included packages is based on
7
- * the manager's config file and matching package folders (which must contain package.json) on disk.
8
- */
9
- function getWorkspacePackagePaths(cwd) {
10
- const utils = (0, implementations_1.getWorkspaceUtilities)(cwd);
11
- return utils?.getWorkspacePackagePaths(cwd) || [];
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: Object.getOwnPropertyDescriptor(all, name).get
9
+ });
10
+ }
11
+ _export(exports, {
12
+ get getWorkspacePackagePaths () {
13
+ return getWorkspacePackagePaths;
14
+ },
15
+ get getWorkspacePackagePathsAsync () {
16
+ return getWorkspacePackagePathsAsync;
17
+ }
18
+ });
19
+ const _fastglob = /*#__PURE__*/ _interop_require_default(require("fast-glob"));
20
+ const _path = /*#__PURE__*/ _interop_require_default(require("path"));
21
+ const _implementations = require("./implementations");
22
+ const _isCachingEnabled = require("../isCachingEnabled.js");
23
+ const _wrapWorkspaceUtility = require("./wrapWorkspaceUtility.js");
24
+ function _interop_require_default(obj) {
25
+ return obj && obj.__esModule ? obj : {
26
+ default: obj
27
+ };
28
+ }
29
+ /** Mapping from root path to resolved package paths, or undefined if there was an error */ const packagePathsCache = new Map();
30
+ const globOptions = {
31
+ absolute: true,
32
+ ignore: [
33
+ "**/node_modules/**",
34
+ "**/__fixtures__/**"
35
+ ],
36
+ stats: false
37
+ };
38
+ function getWorkspacePackagePaths(cwd, managerOverride) {
39
+ return (0, _wrapWorkspaceUtility.wrapWorkspaceUtility)({
40
+ cwd,
41
+ managerOverride,
42
+ description: "workspace package paths",
43
+ impl: ({ manager, root })=>{
44
+ const initialResult = getInitialPathsOrGlobs({
45
+ manager,
46
+ root
47
+ });
48
+ if (!initialResult || "resolvedPaths" in initialResult) {
49
+ return initialResult?.resolvedPaths;
50
+ }
51
+ try {
52
+ const globResults = _fastglob.default.sync(initialResult.globs, {
53
+ cwd: root,
54
+ ...globOptions
55
+ });
56
+ return resolveAndCacheGlobResults({
57
+ root,
58
+ globResults
59
+ });
60
+ } catch (err) {
61
+ (0, _isCachingEnabled.isCachingEnabled)() && packagePathsCache.set(root, undefined);
62
+ throw err;
63
+ }
64
+ }
65
+ });
66
+ }
67
+ async function getWorkspacePackagePathsAsync(cwd, managerOverride) {
68
+ return (0, _wrapWorkspaceUtility.wrapAsyncWorkspaceUtility)({
69
+ cwd,
70
+ managerOverride,
71
+ description: "workspace package paths",
72
+ impl: async ({ manager, root })=>{
73
+ const initialResult = getInitialPathsOrGlobs({
74
+ manager,
75
+ root
76
+ });
77
+ if (!initialResult || "resolvedPaths" in initialResult) {
78
+ return initialResult?.resolvedPaths;
79
+ }
80
+ try {
81
+ const globResults = await (0, _fastglob.default)(initialResult.globs, {
82
+ cwd: root,
83
+ ...globOptions
84
+ });
85
+ return resolveAndCacheGlobResults({
86
+ root,
87
+ globResults
88
+ });
89
+ } catch (err) {
90
+ (0, _isCachingEnabled.isCachingEnabled)() && packagePathsCache.set(root, undefined);
91
+ throw err;
92
+ }
93
+ }
94
+ });
12
95
  }
13
- exports.getWorkspacePackagePaths = getWorkspacePackagePaths;
14
96
  /**
15
- * Get a list of package folder paths in the monorepo. The list of included packages is based on
16
- * the manager's config file and matching package folders (which must contain package.json) on disk.
17
- */
18
- async function getWorkspacePackagePathsAsync(cwd) {
19
- const utils = (0, implementations_1.getWorkspaceUtilities)(cwd);
20
- if (!utils) {
21
- return [];
97
+ * Handles the shared synchronous initial logic:
98
+ * - Used the cached result if available
99
+ * - Else, call `getWorkspacePackagePatterns`
100
+ * - If the results are relative paths (not patterns), resolve, cache, and return them
101
+ * - Else, return the prepared globs for sync or async resolution as appropriate.
102
+ */ function getInitialPathsOrGlobs(params) {
103
+ const canCache = (0, _isCachingEnabled.isCachingEnabled)();
104
+ if (canCache && packagePathsCache.has(params.root)) {
105
+ // Return the cached result, even if it was a failure
106
+ const cachedPaths = packagePathsCache.get(params.root);
107
+ return cachedPaths && {
108
+ resolvedPaths: cachedPaths
109
+ };
22
110
  }
23
- if (!utils.getWorkspacePackagePathsAsync) {
24
- const managerName = (0, implementations_1.getWorkspaceManagerAndRoot)(cwd)?.manager;
25
- throw new Error(`${cwd} is using ${managerName} which has not been converted to async yet`);
111
+ const managerUtilities = (0, _implementations.getWorkspaceUtilities)(params.manager);
112
+ const managerSetting = managerUtilities.getWorkspacePatterns({
113
+ root: params.root
114
+ });
115
+ if (managerSetting?.type === "pattern") {
116
+ return {
117
+ globs: managerSetting.patterns.map((p)=>_path.default.join(p, "package.json").replace(/\\/g, "/"))
118
+ };
119
+ }
120
+ if (managerSetting?.type === "path") {
121
+ const resolvedPaths = managerSetting.patterns.map((p)=>_path.default.resolve(params.root, p));
122
+ if (canCache) {
123
+ packagePathsCache.set(params.root, resolvedPaths);
124
+ }
125
+ return {
126
+ resolvedPaths
127
+ };
128
+ }
129
+ return undefined;
130
+ }
131
+ /**
132
+ * Given the results from globbing package.json files, resolve to package folder paths
133
+ * and cache the results.
134
+ */ function resolveAndCacheGlobResults(params) {
135
+ const { root, globResults } = params;
136
+ const resolvedPaths = globResults.map((packageJsonPath)=>{
137
+ const packagePath = _path.default.dirname(packageJsonPath);
138
+ return _path.default.sep === "/" ? packagePath : packagePath.replace(/\//g, _path.default.sep);
139
+ });
140
+ if ((0, _isCachingEnabled.isCachingEnabled)()) {
141
+ packagePathsCache.set(root, resolvedPaths);
26
142
  }
27
- return utils.getWorkspacePackagePathsAsync(cwd);
143
+ return resolvedPaths;
28
144
  }
29
- exports.getWorkspacePackagePathsAsync = getWorkspacePackagePathsAsync;
30
- //# sourceMappingURL=getWorkspacePackagePaths.js.map