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
package/README.md CHANGED
@@ -20,8 +20,46 @@ Override the `maxBuffer` value for git processes, for example if the repo is ver
20
20
 
21
21
  ### PREFERRED_WORKSPACE_MANAGER
22
22
 
23
- Sometimes if multiple workspace/monorepo manager files are checked in, it's necessary to hint which manager is used: `npm`, `yarn`, `pnpm`, `rush`, or `lerna`.
23
+ Sometimes if multiple workspace/monorepo manager files are checked in, it's necessary to hint which manager is used: `npm`, `yarn`, `pnpm`, `rush`, or `lerna`. Some APIs also accept a `manager` parameter, which is now the preferred method when available.
24
24
 
25
25
  ### VERBOSE
26
26
 
27
27
  Log additional output from certain functions.
28
+
29
+ ## Breaking changes
30
+
31
+ For details of changes in all versions, see the [changelog](https://github.com/microsoft/lage/blob/main/packages/workspace-tools/CHANGELOG.md). This only lists the most significant breaking API changes.
32
+
33
+ ### 0.41.0
34
+
35
+ The following APIs have been renamed for clarity, removed entirely, or consolidated:
36
+
37
+ | Old (removed) | New |
38
+ | ----------------------------- | -------------------------------------- |
39
+ | `getWorkspaces` | `getWorkspaceInfos` |
40
+ | `getWorkspacesAsync` | `getWorkspaceInfosAsync` |
41
+ | `WorkspaceInfo` | `WorkspaceInfos` |
42
+ | `getWorkspaceRoot` | `getWorkspaceManagerRoot` |
43
+ | `listOfWorkspacePackageNames` | `workspaces.map(w => w.name)` |
44
+ | `getPnpmWorkspaceRoot` | `getWorkspaceManagerRoot(cwd, 'pnpm')` |
45
+ | `getRushWorkspaceRoot` | `getWorkspaceManagerRoot(cwd, 'rush')` |
46
+ | `getYarnWorkspaceRoot` | `getWorkspaceManagerRoot(cwd, 'yarn')` |
47
+ | `getPnpmWorkspaces` | `getWorkspaceInfos(cwd, 'pnpm')` |
48
+ | `getRushWorkspaces` | `getWorkspaceInfos(cwd, 'rush')` |
49
+ | `getYarnWorkspaces` | `getWorkspaceInfos(cwd, 'yarn')` |
50
+
51
+ Other changes:
52
+
53
+ - Several functions now return `string[] | undefined` instead of returning an empty array on error:
54
+ - `getAllPackageJsonFiles`, `getAllPackageJsonFilesAsync`
55
+ - `getWorkspacePackagePaths`, `getWorkspacePackagePathsAsync`
56
+ - `getWorkspaceInfos`, `getWorkspaceInfosAsync`
57
+ - `getWorkspaceManagerAndRoot` is now exported if you want to know the manager as well as the root
58
+ - Several functions now have a `manager` param to force using a specific manager:
59
+ - `getWorkspaceManagerRoot`
60
+ - `findProjectRoot` (falls back to the git root and throws if neither is found)
61
+ - `getWorkspacePackagePaths`, `getWorkspacePackagePathsAsync`
62
+ - `getWorkspacePatterns` (new)
63
+ - `getWorkspaceInfos`, `getWorkspaceInfosAsync`
64
+ - `getCatalogs`
65
+ - Some related files have been moved or renamed internally, so deep imports may be broken. Please check the current top-level API to see if the utility you were deep-importing is now exported, and file an issue if not.
@@ -1,5 +1,5 @@
1
- import { getTransitiveConsumers, getTransitiveProviders } from "./transitiveDeps";
2
- import { getPackageDependencies } from "../graph/getPackageDependencies";
1
+ import { getTransitiveConsumers, getTransitiveProviders } from "./transitiveDeps.js";
2
+ import { getPackageDependencies } from "../graph/getPackageDependencies.js";
3
3
  export declare const getTransitiveDependencies: typeof getTransitiveProviders;
4
4
  export { getTransitiveProviders };
5
5
  export declare const getTransitiveDependents: typeof getTransitiveConsumers;
@@ -1,13 +1,32 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getInternalDeps = exports.getTransitiveConsumers = exports.getTransitiveDependents = exports.getTransitiveProviders = exports.getTransitiveDependencies = void 0;
4
- const transitiveDeps_1 = require("./transitiveDeps");
5
- Object.defineProperty(exports, "getTransitiveConsumers", { enumerable: true, get: function () { return transitiveDeps_1.getTransitiveConsumers; } });
6
- Object.defineProperty(exports, "getTransitiveProviders", { enumerable: true, get: function () { return transitiveDeps_1.getTransitiveProviders; } });
7
- const getPackageDependencies_1 = require("../graph/getPackageDependencies");
8
- // Some deprecated functions below for backwards compatibility
9
- exports.getTransitiveDependencies = transitiveDeps_1.getTransitiveProviders;
10
- exports.getTransitiveDependents = transitiveDeps_1.getTransitiveConsumers;
11
- /** @deprecated Do not use */
12
- exports.getInternalDeps = getPackageDependencies_1.getPackageDependencies;
13
- //# sourceMappingURL=index.js.map
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 getInternalDeps () {
13
+ return getInternalDeps;
14
+ },
15
+ get getTransitiveConsumers () {
16
+ return _transitiveDeps.getTransitiveConsumers;
17
+ },
18
+ get getTransitiveDependencies () {
19
+ return getTransitiveDependencies;
20
+ },
21
+ get getTransitiveDependents () {
22
+ return getTransitiveDependents;
23
+ },
24
+ get getTransitiveProviders () {
25
+ return _transitiveDeps.getTransitiveProviders;
26
+ }
27
+ });
28
+ const _transitiveDeps = require("./transitiveDeps.js");
29
+ const _getPackageDependencies = require("../graph/getPackageDependencies.js");
30
+ const getTransitiveDependencies = _transitiveDeps.getTransitiveProviders;
31
+ const getTransitiveDependents = _transitiveDeps.getTransitiveConsumers;
32
+ const getInternalDeps = _getPackageDependencies.getPackageDependencies;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/dependencies/index.ts"],"names":[],"mappings":";;;AAAA,qDAAkF;AAWzE,uGAXA,uCAAsB,OAWA;AAJtB,uGAPwB,uCAAsB,OAOxB;AAN/B,4EAAyE;AAEzE,8DAA8D;AAEjD,QAAA,yBAAyB,GAAG,uCAAsB,CAAC;AAInD,QAAA,uBAAuB,GAAG,uCAAsB,CAAC;AAI9D,6BAA6B;AAChB,QAAA,eAAe,GAAG,+CAAsB,CAAC"}
1
+ {"version":3,"sources":["../../src/dependencies/index.ts"],"sourcesContent":["import { getTransitiveConsumers, getTransitiveProviders } from \"./transitiveDeps.js\";\nimport { getPackageDependencies } from \"../graph/getPackageDependencies.js\";\n\n// Some deprecated functions below for backwards compatibility\n\nexport const getTransitiveDependencies = getTransitiveProviders;\n\nexport { getTransitiveProviders };\n\nexport const getTransitiveDependents = getTransitiveConsumers;\n\nexport { getTransitiveConsumers };\n\n/** @deprecated Do not use */\nexport const getInternalDeps = getPackageDependencies;\n"],"names":["getInternalDeps","getTransitiveConsumers","getTransitiveDependencies","getTransitiveDependents","getTransitiveProviders","getPackageDependencies"],"mappings":";;;;;;;;;;;QAcaA;eAAAA;;QAHJC;eAAAA,sCAAsB;;QANlBC;eAAAA;;QAIAC;eAAAA;;QAFJC;eAAAA,sCAAsB;;;gCAPgC;wCACxB;AAIhC,MAAMF,4BAA4BE,sCAAsB;AAIxD,MAAMD,0BAA0BF,sCAAsB;AAKtD,MAAMD,kBAAkBK,8CAAsB"}
@@ -1,4 +1,4 @@
1
- import { PackageInfos } from "../types/PackageInfo";
1
+ import { type PackageInfos } from "../types/PackageInfo.js";
2
2
  export declare function getDependentMap(packages: PackageInfos): Map<string, Set<string>>;
3
3
  /**
4
4
  * For a package graph of `a->b->c` (where `b` depends on `a`), transitive consumers of `a` are `b` & `c`
@@ -1,37 +1,65 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTransitiveProviders = exports.getTransitiveConsumers = exports.getDependentMap = void 0;
4
- const getPackageDependencies_1 = require("../graph/getPackageDependencies");
5
- const isCachingEnabled_1 = require("../isCachingEnabled");
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 getDependentMap () {
13
+ return getDependentMap;
14
+ },
15
+ get getTransitiveConsumers () {
16
+ return getTransitiveConsumers;
17
+ },
18
+ get getTransitiveProviders () {
19
+ return getTransitiveProviders;
20
+ }
21
+ });
22
+ const _getPackageDependencies = require("../graph/getPackageDependencies.js");
23
+ const _isCachingEnabled = require("../isCachingEnabled.js");
6
24
  const graphCache = new Map();
7
25
  function memoizedKey(packages, scope = []) {
8
- return JSON.stringify({ packages, scope });
26
+ return JSON.stringify({
27
+ packages,
28
+ scope
29
+ });
9
30
  }
10
31
  function getPackageGraph(packages, scope = []) {
11
32
  const internalPackages = new Set(Object.keys(packages));
12
33
  const key = memoizedKey(packages, scope);
13
- if ((0, isCachingEnabled_1.isCachingEnabled)() && graphCache.has(key)) {
34
+ if ((0, _isCachingEnabled.isCachingEnabled)() && graphCache.has(key)) {
14
35
  return graphCache.get(key);
15
36
  }
16
37
  const edges = [];
17
38
  const visited = new Set();
18
- const stack = scope.length > 0 ? [...scope] : Object.keys(packages);
19
- while (stack.length > 0) {
39
+ const stack = scope.length > 0 ? [
40
+ ...scope
41
+ ] : Object.keys(packages);
42
+ while(stack.length > 0){
20
43
  const pkg = stack.pop();
21
44
  if (visited.has(pkg)) {
22
45
  continue;
23
46
  }
24
47
  visited.add(pkg);
25
48
  const info = packages[pkg];
26
- const deps = (0, getPackageDependencies_1.getPackageDependencies)(info, internalPackages);
49
+ const deps = (0, _getPackageDependencies.getPackageDependencies)(info, internalPackages);
27
50
  if (deps.length > 0) {
28
- for (const dep of deps) {
51
+ for (const dep of deps){
29
52
  stack.push(dep);
30
- edges.push([dep, pkg]);
53
+ edges.push([
54
+ dep,
55
+ pkg
56
+ ]);
31
57
  }
32
- }
33
- else {
34
- edges.push([null, pkg]);
58
+ } else {
59
+ edges.push([
60
+ null,
61
+ pkg
62
+ ]);
35
63
  }
36
64
  }
37
65
  graphCache.set(key, edges);
@@ -40,7 +68,7 @@ function getPackageGraph(packages, scope = []) {
40
68
  function getDependentMap(packages) {
41
69
  const graph = getPackageGraph(packages);
42
70
  const map = new Map();
43
- for (const [from, to] of graph) {
71
+ for (const [from, to] of graph){
44
72
  if (!map.has(to)) {
45
73
  map.set(to, new Set());
46
74
  }
@@ -50,52 +78,45 @@ function getDependentMap(packages) {
50
78
  }
51
79
  return map;
52
80
  }
53
- exports.getDependentMap = getDependentMap;
54
- /**
55
- * For a package graph of `a->b->c` (where `b` depends on `a`), transitive consumers of `a` are `b` & `c`
56
- * and their consumers (or what are the consequences of `a`)
57
- * @deprecated Do not use
58
- */
59
81
  function getTransitiveConsumers(targets, packages, scope = []) {
60
82
  const graph = getPackageGraph(packages, scope);
61
- const pkgQueue = [...targets];
83
+ const pkgQueue = [
84
+ ...targets
85
+ ];
62
86
  const visited = new Set();
63
- while (pkgQueue.length > 0) {
87
+ while(pkgQueue.length > 0){
64
88
  const pkg = pkgQueue.shift();
65
89
  if (!visited.has(pkg)) {
66
90
  visited.add(pkg);
67
- for (const [from, to] of graph) {
91
+ for (const [from, to] of graph){
68
92
  if (from === pkg) {
69
93
  pkgQueue.push(to);
70
94
  }
71
95
  }
72
96
  }
73
97
  }
74
- return [...visited].filter((pkg) => !targets.includes(pkg));
98
+ return [
99
+ ...visited
100
+ ].filter((pkg)=>!targets.includes(pkg));
75
101
  }
76
- exports.getTransitiveConsumers = getTransitiveConsumers;
77
- /**
78
- * For a package graph of `a->b->c` (where `b` depends on `a`), transitive providers of `c` are `a` & `b`
79
- * and their providers (or what is needed to satisfy `c`)
80
- *
81
- * @deprecated Do not use
82
- */
83
102
  function getTransitiveProviders(targets, packages) {
84
103
  const graph = getPackageGraph(packages);
85
- const pkgQueue = [...targets];
104
+ const pkgQueue = [
105
+ ...targets
106
+ ];
86
107
  const visited = new Set();
87
- while (pkgQueue.length > 0) {
108
+ while(pkgQueue.length > 0){
88
109
  const pkg = pkgQueue.shift();
89
110
  if (!visited.has(pkg)) {
90
111
  visited.add(pkg);
91
- for (const [from, to] of graph) {
112
+ for (const [from, to] of graph){
92
113
  if (to === pkg && from) {
93
114
  pkgQueue.push(from);
94
115
  }
95
116
  }
96
117
  }
97
118
  }
98
- return [...visited].filter((pkg) => !targets.includes(pkg));
119
+ return [
120
+ ...visited
121
+ ].filter((pkg)=>!targets.includes(pkg));
99
122
  }
100
- exports.getTransitiveProviders = getTransitiveProviders;
101
- //# sourceMappingURL=transitiveDeps.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"transitiveDeps.js","sourceRoot":"","sources":["../../src/dependencies/transitiveDeps.ts"],"names":[],"mappings":";;;AACA,4EAAyE;AACzE,0DAAuD;AAEvD,MAAM,UAAU,GAAG,IAAI,GAAG,EAAqC,CAAC;AAEhE,SAAS,WAAW,CAAC,QAAsB,EAAE,QAAkB,EAAE;IAC/D,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;AAC7C,CAAC;AAED,SAAS,eAAe,CAAC,QAAsB,EAAE,QAAkB,EAAE;IACnE,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IACxD,MAAM,GAAG,GAAG,WAAW,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAEzC,IAAI,IAAA,mCAAgB,GAAE,IAAI,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;QAC7C,OAAO,UAAU,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC;KAC7B;IAED,MAAM,KAAK,GAA8B,EAAE,CAAC;IAE5C,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAClC,MAAM,KAAK,GAAa,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CA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QAAQ,CAAC,KAAK,EAAG,CAAC;QAE9B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YACrB,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAEjB,KAAK,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,EAAE;gBAC9B,IAAI,EAAE,KAAK,GAAG,IAAI,IAAI,EAAE;oBACtB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;iBACrB;aACF;SACF;KACF;IAED,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;AAC9D,CAAC;AApBD,wDAoBC"}
1
+ {"version":3,"sources":["../../src/dependencies/transitiveDeps.ts"],"sourcesContent":["import { type PackageInfos } from \"../types/PackageInfo.js\";\nimport { getPackageDependencies } from \"../graph/getPackageDependencies.js\";\nimport { isCachingEnabled } from \"../isCachingEnabled.js\";\n\nconst graphCache = new Map<string, [string | null, string][]>();\n\nfunction memoizedKey(packages: PackageInfos, scope: string[] = []) {\n return JSON.stringify({ packages, scope });\n}\n\nfunction getPackageGraph(packages: PackageInfos, scope: string[] = []) {\n const internalPackages = new Set(Object.keys(packages));\n const key = memoizedKey(packages, scope);\n\n if (isCachingEnabled() && graphCache.has(key)) {\n return graphCache.get(key)!;\n }\n\n const edges: [string | null, string][] = [];\n\n const visited = new Set<string>();\n const stack: string[] = scope.length > 0 ? [...scope] : Object.keys(packages);\n\n while (stack.length > 0) {\n const pkg = stack.pop()!;\n\n if (visited.has(pkg)) {\n continue;\n }\n\n visited.add(pkg);\n\n const info = packages[pkg];\n const deps = getPackageDependencies(info, internalPackages);\n\n if (deps.length > 0) {\n for (const dep of deps) {\n stack.push(dep);\n edges.push([dep, pkg]);\n }\n } else {\n edges.push([null, pkg]);\n }\n }\n\n graphCache.set(key, edges);\n\n return edges;\n}\n\nexport function getDependentMap(packages: PackageInfos): Map<string, Set<string>> {\n const graph = getPackageGraph(packages);\n const map = new Map<string, Set<string>>();\n for (const [from, to] of graph) {\n if (!map.has(to)) {\n map.set(to, new Set());\n }\n\n if (from) {\n map.get(to)!.add(from);\n }\n }\n\n return map;\n}\n\n/**\n * For a package graph of `a->b->c` (where `b` depends on `a`), transitive consumers of `a` are `b` & `c`\n * and their consumers (or what are the consequences of `a`)\n * @deprecated Do not use\n */\nexport function getTransitiveConsumers(targets: string[], packages: PackageInfos, scope: string[] = []): string[] {\n const graph = getPackageGraph(packages, scope);\n const pkgQueue: string[] = [...targets];\n const visited = new Set<string>();\n\n while (pkgQueue.length > 0) {\n const pkg = pkgQueue.shift()!;\n\n if (!visited.has(pkg)) {\n visited.add(pkg);\n\n for (const [from, to] of graph) {\n if (from === pkg) {\n pkgQueue.push(to);\n }\n }\n }\n }\n\n return [...visited].filter((pkg) => !targets.includes(pkg));\n}\n\n/**\n * For a package graph of `a->b->c` (where `b` depends on `a`), transitive providers of `c` are `a` & `b`\n * and their providers (or what is needed to satisfy `c`)\n *\n * @deprecated Do not use\n */\nexport function getTransitiveProviders(targets: string[], packages: PackageInfos): string[] {\n const graph = getPackageGraph(packages);\n const pkgQueue: string[] = [...targets];\n const visited = new Set<string>();\n\n while (pkgQueue.length > 0) {\n const pkg = pkgQueue.shift()!;\n\n if (!visited.has(pkg)) {\n visited.add(pkg);\n\n for (const [from, to] of graph) {\n if (to === pkg && from) {\n pkgQueue.push(from);\n }\n }\n }\n }\n\n return [...visited].filter((pkg) => !targets.includes(pkg));\n}\n"],"names":["getDependentMap","getTransitiveConsumers","getTransitiveProviders","graphCache","Map","memoizedKey","packages","scope","JSON","stringify","getPackageGraph","internalPackages","Set","Object","keys","key","isCachingEnabled","has","get","edges","visited","stack","length","pkg","pop","add","info","deps","getPackageDependencies","dep","push","set","graph","map","from","to","targets","pkgQueue","shift","filter","includes"],"mappings":";;;;;;;;;;;QAkDgBA;e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,CAACa,QAAQI,QAAQ,CAACjB;AACxD"}
@@ -1,13 +1,15 @@
1
- import type { PackageInfo } from "./types/PackageInfo";
1
+ import type { PackageInfo } from "./types/PackageInfo.js";
2
2
  /**
3
3
  * Read package.json from the given path if it exists.
4
- * Logs a warning if it doesn't exist, or there's an error reading or parsing it.
5
- * @returns The package info, or undefined if it doesn't exist or can't be read
4
+ *
5
+ * @returns The package info, or undefined if it doesn't exist or can't be read.
6
+ * (Logs verbose warnings instead of throwing on error.)
6
7
  */
7
8
  export declare function getPackageInfo(cwd: string): PackageInfo | undefined;
8
9
  /**
9
10
  * Read package.json from the given path if it exists.
10
- * Logs a warning if it doesn't exist, or there's an error reading or parsing it.
11
- * @returns The package info, or undefined if it doesn't exist or can't be read
11
+ *
12
+ * @returns The package info, or undefined if it doesn't exist or can't be read.
13
+ * (Logs verbose warnings instead of throwing on error.)
12
14
  */
13
15
  export declare function getPackageInfoAsync(cwd: string): Promise<PackageInfo | undefined>;
@@ -1,52 +1,59 @@
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.getPackageInfoAsync = exports.getPackageInfo = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- const promises_1 = __importDefault(require("fs/promises"));
9
- const path_1 = __importDefault(require("path"));
10
- const infoFromPackageJson_1 = require("./infoFromPackageJson");
11
- const logging_1 = require("./logging");
12
- /**
13
- * Read package.json from the given path if it exists.
14
- * Logs a warning if it doesn't exist, or there's an error reading or parsing it.
15
- * @returns The package info, or undefined if it doesn't exist or can't be read
16
- */
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 getPackageInfo () {
13
+ return getPackageInfo;
14
+ },
15
+ get getPackageInfoAsync () {
16
+ return getPackageInfoAsync;
17
+ }
18
+ });
19
+ const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
20
+ const _promises = /*#__PURE__*/ _interop_require_default(require("fs/promises"));
21
+ const _path = /*#__PURE__*/ _interop_require_default(require("path"));
22
+ const _logging = require("./logging.js");
23
+ function _interop_require_default(obj) {
24
+ return obj && obj.__esModule ? obj : {
25
+ default: obj
26
+ };
27
+ }
17
28
  function getPackageInfo(cwd) {
18
- const packageJsonPath = path_1.default.join(cwd, "package.json");
29
+ const packageJsonPath = _path.default.join(cwd, "package.json");
19
30
  try {
20
- if (!fs_1.default.existsSync(packageJsonPath)) {
21
- (0, logging_1.logVerboseWarning)(`File does not exist: ${packageJsonPath}`);
31
+ if (!_fs.default.existsSync(packageJsonPath)) {
32
+ (0, _logging.logVerboseWarning)(`File does not exist: ${packageJsonPath}`);
22
33
  return undefined;
23
34
  }
24
- const packageJson = JSON.parse(fs_1.default.readFileSync(packageJsonPath, "utf-8"));
25
- return (0, infoFromPackageJson_1.infoFromPackageJson)(packageJson, packageJsonPath);
26
- }
27
- catch (e) {
28
- (0, logging_1.logVerboseWarning)(`Error reading or parsing ${packageJsonPath}: ${e?.message || e}`);
35
+ const packageJson = JSON.parse(_fs.default.readFileSync(packageJsonPath, "utf-8"));
36
+ return {
37
+ ...packageJson,
38
+ packageJsonPath
39
+ };
40
+ } catch (e) {
41
+ (0, _logging.logVerboseWarning)(`Error reading or parsing ${packageJsonPath}: ${e?.message || e}`);
29
42
  }
30
43
  }
31
- exports.getPackageInfo = getPackageInfo;
32
- /**
33
- * Read package.json from the given path if it exists.
34
- * Logs a warning if it doesn't exist, or there's an error reading or parsing it.
35
- * @returns The package info, or undefined if it doesn't exist or can't be read
36
- */
37
44
  async function getPackageInfoAsync(cwd) {
38
- const packageJsonPath = path_1.default.join(cwd, "package.json");
45
+ const packageJsonPath = _path.default.join(cwd, "package.json");
39
46
  try {
40
- if (!fs_1.default.existsSync(packageJsonPath)) {
41
- (0, logging_1.logVerboseWarning)(`File does not exist: ${packageJsonPath}`);
47
+ if (!_fs.default.existsSync(packageJsonPath)) {
48
+ (0, _logging.logVerboseWarning)(`File does not exist: ${packageJsonPath}`);
42
49
  return undefined;
43
50
  }
44
- const packageJson = JSON.parse(await promises_1.default.readFile(packageJsonPath, "utf-8"));
45
- return (0, infoFromPackageJson_1.infoFromPackageJson)(packageJson, packageJsonPath);
46
- }
47
- catch (e) {
48
- (0, logging_1.logVerboseWarning)(`Error reading or parsing ${packageJsonPath}: ${e?.message || e}`);
51
+ const packageJson = JSON.parse(await _promises.default.readFile(packageJsonPath, "utf-8"));
52
+ return {
53
+ ...packageJson,
54
+ packageJsonPath
55
+ };
56
+ } catch (e) {
57
+ (0, _logging.logVerboseWarning)(`Error reading or parsing ${packageJsonPath}: ${e?.message || e}`);
49
58
  }
50
59
  }
51
- exports.getPackageInfoAsync = getPackageInfoAsync;
52
- //# sourceMappingURL=getPackageInfo.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getPackageInfo.js","sourceRoot":"","sources":["../src/getPackageInfo.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,2DAAqC;AACrC,gDAAwB;AAExB,+DAA4D;AAC5D,uCAA8C;AAE9C;;;;GAIG;AACH,SAAgB,cAAc,CAAC,GAAW;IACxC,MAAM,eAAe,GAAG,cAAI,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;IACvD,IAAI;QACF,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE;YACnC,IAAA,2BAAiB,EAAC,wBAAwB,eAAe,EAAE,CAAC,CAAC;YAC7D,OAAO,SAAS,CAAC;SAClB;QAED,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,YAAE,CAAC,YAAY,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC,CAAC;QAC1E,OAAO,IAAA,yCAAmB,EAAC,WAAW,EAAE,eAAe,CAAC,CAAC;KAC1D;IAAC,OAAO,CAAC,EAAE;QACV,IAAA,2BAAiB,EAAC,4BAA4B,eAAe,KAAM,CAAW,EAAE,OAAO,IAAI,CAAC,EAAE,CAAC,CAAC;KACjG;AACH,CAAC;AAbD,wCAaC;AAED;;;;GAIG;AACI,KAAK,UAAU,mBAAmB,CAAC,GAAW;IACnD,MAAM,eAAe,GAAG,cAAI,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;IACvD,IAAI;QACF,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE;YACnC,IAAA,2BAAiB,EAAC,wBAAwB,eAAe,EAAE,CAAC,CAAC;YAC7D,OAAO,SAAS,CAAC;SAClB;QAED,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,kBAAU,CAAC,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC,CAAC;QACpF,OAAO,IAAA,yCAAmB,EAAC,WAAW,EAAE,eAAe,CAAC,CAAC;KAC1D;IAAC,OAAO,CAAC,EAAE;QACV,IAAA,2BAAiB,EAAC,4BAA4B,eAAe,KAAM,CAAW,EAAE,OAAO,IAAI,CAAC,EAAE,CAAC,CAAC;KACjG;AACH,CAAC;AAbD,kDAaC"}
1
+ {"version":3,"sources":["../src/getPackageInfo.ts"],"sourcesContent":["import fs from \"fs\";\nimport fsPromises from \"fs/promises\";\nimport path from \"path\";\nimport type { PackageInfo } from \"./types/PackageInfo.js\";\nimport { logVerboseWarning } from \"./logging.js\";\n\n/**\n * Read package.json from the given path if it exists.\n *\n * @returns The package info, or undefined if it doesn't exist or can't be read.\n * (Logs verbose warnings instead of throwing on error.)\n */\nexport function getPackageInfo(cwd: string): PackageInfo | undefined {\n const packageJsonPath = path.join(cwd, \"package.json\");\n try {\n if (!fs.existsSync(packageJsonPath)) {\n logVerboseWarning(`File does not exist: ${packageJsonPath}`);\n return undefined;\n }\n\n const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, \"utf-8\"));\n return { ...packageJson, packageJsonPath };\n } catch (e) {\n logVerboseWarning(`Error reading or parsing ${packageJsonPath}: ${(e as Error)?.message || e}`);\n }\n}\n\n/**\n * Read package.json from the given path if it exists.\n *\n * @returns The package info, or undefined if it doesn't exist or can't be read.\n * (Logs verbose warnings instead of throwing on error.)\n */\nexport async function getPackageInfoAsync(cwd: string): Promise<PackageInfo | undefined> {\n const packageJsonPath = path.join(cwd, \"package.json\");\n try {\n if (!fs.existsSync(packageJsonPath)) {\n logVerboseWarning(`File does not exist: ${packageJsonPath}`);\n return undefined;\n }\n\n const packageJson = JSON.parse(await fsPromises.readFile(packageJsonPath, \"utf-8\"));\n return { ...packageJson, packageJsonPath };\n } catch (e) {\n logVerboseWarning(`Error reading or parsing ${packageJsonPath}: ${(e as Error)?.message || e}`);\n }\n}\n"],"names":["getPackageInfo","getPackageInfoAsync","cwd","packageJsonPath","path","join","fs","existsSync","logVerboseWarning","undefined","packageJson","JSON","parse","readFileSync","e","message","fsPromises","readFile"],"mappings":";;;;;;;;;;;QAYgBA;eAAAA;;QAqBMC;eAAAA;;;2DAjCP;iEACQ;6DACN;yBAEiB;;;;;;AAQ3B,SAASD,eAAeE,GAAW;IACxC,MAAMC,kBAAkBC,aAAI,CAACC,IAAI,CAACH,KAAK;IACvC,IAAI;QACF,IAAI,CAACI,WAAE,CAACC,UAAU,CAACJ,kBAAkB;YACnCK,IAAAA,0BAAiB,EAAC,CAAC,qBAAqB,EAAEL,iBAAiB;YAC3D,OAAOM;QACT;QAEA,MAAMC,cAAcC,KAAKC,KAAK,CAACN,WAAE,CAACO,YAAY,CAACV,iBAAiB;QAChE,OAAO;YAAE,GAAGO,WAAW;YAAEP;QAAgB;IAC3C,EAAE,OAAOW,GAAG;QACVN,IAAAA,0BAAiB,EAAC,CAAC,yBAAyB,EAAEL,gBAAgB,EAAE,EAAE,AAACW,GAAaC,WAAWD,GAAG;IAChG;AACF;AAQO,eAAeb,oBAAoBC,GAAW;IACnD,MAAMC,kBAAkBC,aAAI,CAACC,IAAI,CAACH,KAAK;IACvC,IAAI;QACF,IAAI,CAACI,WAAE,CAACC,UAAU,CAACJ,kBAAkB;YACnCK,IAAAA,0BAAiB,EAAC,CAAC,qBAAqB,EAAEL,iBAAiB;YAC3D,OAAOM;QACT;QAEA,MAAMC,cAAcC,KAAKC,KAAK,CAAC,MAAMI,iBAAU,CAACC,QAAQ,CAACd,iBAAiB;QAC1E,OAAO;YAAE,GAAGO,WAAW;YAAEP;QAAgB;IAC3C,EAAE,OAAOW,GAAG;QACVN,IAAAA,0BAAiB,EAAC,CAAC,yBAAyB,EAAEL,gBAAgB,EAAE,EAAE,AAACW,GAAaC,WAAWD,GAAG;IAChG;AACF"}
@@ -1,17 +1,40 @@
1
- import { PackageInfos } from "./types/PackageInfo";
1
+ import { type PackageInfos } from "./types/PackageInfo.js";
2
+ import type { WorkspaceManager } from "./types/WorkspaceManager.js";
2
3
  /**
3
- * Read all the package.json files in a monorepo.
4
+ * Read all the package.json files in a monorepo and return a mapping from package name to info.
4
5
  * Only works for monorepos which use a supported workspace/monorepo manager.
6
+ *
7
+ * Notes:
8
+ * - The workspace manager, root, and list of package paths for `cwd` are cached internally,
9
+ * but the package contents are not.
10
+ * - To get an array listing package names, paths, and contents, use `getWorkspaceInfos` instead.
11
+ * - If no workspace config is found, it will return info for the root package.json if one exists.
12
+ * (This is different than `getWorkspaceInfos`.)
13
+ *
5
14
  * @param cwd Start looking for the manager config from here
15
+ * @param managerOverride Workspace/monorepo manager to use instead of auto-detecting
16
+ *
17
+ * @returns Mapping from package name to package info.
18
+ * If no workspace config is found, it will return info for the root package.json if one exists.
19
+ * Will be empty on error (it logs verbose warnings instead of throwing).
6
20
  */
7
- export declare function getPackageInfos(cwd: string): PackageInfos;
21
+ export declare function getPackageInfos(cwd: string, managerOverride?: WorkspaceManager): PackageInfos;
8
22
  /**
9
- * Read all the package.json files in a monorepo. Only works for monorepos which
10
- * use a supported workspace/monorepo manager.
23
+ * Read all the package.json files in a monorepo and return a mapping from package name to info.
24
+ * Only works for monorepos which use a supported workspace/monorepo manager.
11
25
  *
12
- * NOTE: As of writing, this will start promises to read all package.json files in parallel,
13
- * without direct concurrency control.
26
+ * Notes:
27
+ * - **WARNING**: As of writing, this will start promises to read all package.json files in
28
+ * parallel, without direct concurrency control.
29
+ * - The workspace manager, root, and list of package paths for `cwd` are cached internally,
30
+ * but the package contents are not.
31
+ * - To get an array listing package names, paths, and contents, use `getWorkspaceInfos` instead.
14
32
  *
15
33
  * @param cwd Start looking for the manager config from here
34
+ * @param managerOverride Workspace/monorepo manager to use instead of auto-detecting
35
+ *
36
+ * @returns Mapping from package name to package info.
37
+ * If no workspace config is found, it will return info for the root package.json if one exists.
38
+ * Will be empty on error (it logs verbose warnings instead of throwing).
16
39
  */
17
- export declare function getPackageInfosAsync(cwd: string): Promise<PackageInfos>;
40
+ export declare function getPackageInfosAsync(cwd: string, managerOverride?: WorkspaceManager): Promise<PackageInfos>;
@@ -1,54 +1,54 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPackageInfosAsync = exports.getPackageInfos = void 0;
4
- const getWorkspaces_1 = require("./workspaces/getWorkspaces");
5
- const getPackageInfo_1 = require("./getPackageInfo");
6
- /**
7
- * Read all the package.json files in a monorepo.
8
- * Only works for monorepos which use a supported workspace/monorepo manager.
9
- * @param cwd Start looking for the manager config from here
10
- */
11
- function getPackageInfos(cwd) {
12
- const packageInfos = {};
13
- const workspacePackages = (0, getWorkspaces_1.getWorkspaces)(cwd);
14
- if (workspacePackages.length) {
15
- for (const pkg of workspacePackages) {
16
- packageInfos[pkg.name] = pkg.packageJson;
17
- }
18
- }
19
- else {
20
- const rootInfo = (0, getPackageInfo_1.getPackageInfo)(cwd);
21
- if (rootInfo) {
22
- packageInfos[rootInfo.name] = rootInfo;
23
- }
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 getPackageInfos () {
13
+ return getPackageInfos;
14
+ },
15
+ get getPackageInfosAsync () {
16
+ return getPackageInfosAsync;
24
17
  }
25
- return packageInfos;
18
+ });
19
+ const _getWorkspaceInfos = require("./workspaces/getWorkspaceInfos.js");
20
+ const _getPackageInfo = require("./getPackageInfo.js");
21
+ const _paths = require("./paths.js");
22
+ function getPackageInfos(cwd, managerOverride) {
23
+ const workspacePackages = (0, _getWorkspaceInfos.getWorkspaceInfos)(cwd, managerOverride);
24
+ return buildPackageInfos({
25
+ cwd,
26
+ workspacePackages
27
+ });
28
+ }
29
+ async function getPackageInfosAsync(cwd, managerOverride) {
30
+ const workspacePackages = await (0, _getWorkspaceInfos.getWorkspaceInfosAsync)(cwd, managerOverride);
31
+ return buildPackageInfos({
32
+ cwd,
33
+ workspacePackages
34
+ });
26
35
  }
27
- exports.getPackageInfos = getPackageInfos;
28
36
  /**
29
- * Read all the package.json files in a monorepo. Only works for monorepos which
30
- * use a supported workspace/monorepo manager.
31
- *
32
- * NOTE: As of writing, this will start promises to read all package.json files in parallel,
33
- * without direct concurrency control.
34
- *
35
- * @param cwd Start looking for the manager config from here
36
- */
37
- async function getPackageInfosAsync(cwd) {
37
+ * Convert an array of workspace package infos into a name-to-packageInfo map.
38
+ * If there are no workspace packages, reads the root package.json instead.
39
+ */ function buildPackageInfos(params) {
40
+ const { cwd, workspacePackages } = params;
38
41
  const packageInfos = {};
39
- const workspacePackages = await (0, getWorkspaces_1.getWorkspacesAsync)(cwd);
40
- if (workspacePackages.length) {
41
- for (const pkg of workspacePackages) {
42
+ if (workspacePackages?.length) {
43
+ for (const pkg of workspacePackages){
42
44
  packageInfos[pkg.name] = pkg.packageJson;
43
45
  }
44
- }
45
- else {
46
- const rootInfo = (0, getPackageInfo_1.getPackageInfo)(cwd);
46
+ } else {
47
+ const packageRoot = (0, _paths.findPackageRoot)(cwd);
48
+ const rootInfo = packageRoot && (0, _getPackageInfo.getPackageInfo)(packageRoot);
47
49
  if (rootInfo) {
48
50
  packageInfos[rootInfo.name] = rootInfo;
49
51
  }
50
52
  }
51
53
  return packageInfos;
52
54
  }
53
- exports.getPackageInfosAsync = getPackageInfosAsync;
54
- //# sourceMappingURL=getPackageInfos.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getPackageInfos.js","sourceRoot":"","sources":["../src/getPackageInfos.ts"],"names":[],"mappings":";;;AACA,8DAA+E;AAC/E,qDAAkD;AAElD;;;;GAIG;AACH,SAAgB,eAAe,CAAC,GAAW;IACzC,MAAM,YAAY,GAAiB,EAAE,CAAC;IACtC,MAAM,iBAAiB,GAAG,IAAA,6BAAa,EAAC,GAAG,CAAC,CAAC;IAE7C,IAAI,iBAAiB,CAAC,MAAM,EAAE;QAC5B,KAAK,MAAM,GAAG,IAAI,iBAAiB,EAAE;YACnC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,WAAW,CAAC;SAC1C;KACF;SAAM;QACL,MAAM,QAAQ,GAAG,IAAA,+BAAc,EAAC,GAAG,CAAC,CAAC;QACrC,IAAI,QAAQ,EAAE;YACZ,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC;SACxC;KACF;IAED,OAAO,YAAY,CAAC;AACtB,CAAC;AAhBD,0CAgBC;AAED;;;;;;;;GAQG;AACI,KAAK,UAAU,oBAAoB,CAAC,GAAW;IACpD,MAAM,YAAY,GAAiB,EAAE,CAAC;IACtC,MAAM,iBAAiB,GAAG,MAAM,IAAA,kCAAkB,EAAC,GAAG,CAAC,CAAC;IAExD,IAAI,iBAAiB,CAAC,MAAM,EAAE;QAC5B,KAAK,MAAM,GAAG,IAAI,iBAAiB,EAAE;YACnC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,WAAW,CAAC;SAC1C;KACF;SAAM;QACL,MAAM,QAAQ,GAAG,IAAA,+BAAc,EAAC,GAAG,CAAC,CAAC;QACrC,IAAI,QAAQ,EAAE;YACZ,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC;SACxC;KACF;IAED,OAAO,YAAY,CAAC;AACtB,CAAC;AAhBD,oDAgBC"}
1
+ {"version":3,"sources":["../src/getPackageInfos.ts"],"sourcesContent":["import { type PackageInfos } from \"./types/PackageInfo.js\";\nimport { getWorkspaceInfos, getWorkspaceInfosAsync } from \"./workspaces/getWorkspaceInfos.js\";\nimport { getPackageInfo } from \"./getPackageInfo.js\";\nimport type { WorkspacePackageInfo } from \"./types/WorkspaceInfo.js\";\nimport type { WorkspaceManager } from \"./types/WorkspaceManager.js\";\nimport { findPackageRoot } from \"./paths.js\";\n\n/**\n * Read all the package.json files in a monorepo and return a mapping from package name to info.\n * Only works for monorepos which use a supported workspace/monorepo manager.\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 array listing package names, paths, and contents, use `getWorkspaceInfos` instead.\n * - If no workspace config is found, it will return info for the root package.json if one exists.\n * (This is different than `getWorkspaceInfos`.)\n *\n * @param cwd Start looking for the manager config from here\n * @param managerOverride Workspace/monorepo manager to use instead of auto-detecting\n *\n * @returns Mapping from package name to package info.\n * If no workspace config is found, it will return info for the root package.json if one exists.\n * Will be empty on error (it logs verbose warnings instead of throwing).\n */\nexport function getPackageInfos(cwd: string, managerOverride?: WorkspaceManager): PackageInfos {\n const workspacePackages = getWorkspaceInfos(cwd, managerOverride);\n return buildPackageInfos({ cwd, workspacePackages });\n}\n\n/**\n * Read all the package.json files in a monorepo and return a mapping from package name to info.\n * Only works for monorepos which use a supported workspace/monorepo manager.\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 array listing package names, paths, and contents, use `getWorkspaceInfos` instead.\n *\n * @param cwd Start looking for the manager config from here\n * @param managerOverride Workspace/monorepo manager to use instead of auto-detecting\n *\n * @returns Mapping from package name to package info.\n * If no workspace config is found, it will return info for the root package.json if one exists.\n * Will be empty on error (it logs verbose warnings instead of throwing).\n */\nexport async function getPackageInfosAsync(cwd: string, managerOverride?: WorkspaceManager): Promise<PackageInfos> {\n const workspacePackages = await getWorkspaceInfosAsync(cwd, managerOverride);\n return buildPackageInfos({ cwd, workspacePackages });\n}\n\n/**\n * Convert an array of workspace package infos into a name-to-packageInfo map.\n * If there are no workspace packages, reads the root package.json instead.\n */\nfunction buildPackageInfos(params: {\n cwd: string;\n workspacePackages: WorkspacePackageInfo[] | undefined;\n}): PackageInfos {\n const { cwd, workspacePackages } = params;\n const packageInfos: PackageInfos = {};\n\n if (workspacePackages?.length) {\n for (const pkg of workspacePackages) {\n packageInfos[pkg.name] = pkg.packageJson;\n }\n } else {\n const packageRoot = findPackageRoot(cwd);\n const rootInfo = packageRoot && getPackageInfo(packageRoot);\n if (rootInfo) {\n packageInfos[rootInfo.name] = rootInfo;\n }\n }\n\n return packageInfos;\n}\n"],"names":["getPackageInfos","getPackageInfosAsync","cwd","managerOverride","workspacePackages","getWorkspaceInfos","buildPackageInfos","getWorkspaceInfosAsync","params","packageInfos","length","pkg","name","packageJson","packageRoot","findPackageRoot","rootInfo","getPackageInfo"],"mappings":";;;;;;;;;;;QAyBgBA;eAAAA;;QAuBMC;eAAAA;;;mCA/CoC;gCAC3B;uBAGC;AAoBzB,SAASD,gBAAgBE,GAAW,EAAEC,eAAkC;IAC7E,MAAMC,oBAAoBC,IAAAA,oCAAiB,EAACH,KAAKC;IACjD,OAAOG,kBAAkB;QAAEJ;QAAKE;IAAkB;AACpD;AAoBO,eAAeH,qBAAqBC,GAAW,EAAEC,eAAkC;IACxF,MAAMC,oBAAoB,MAAMG,IAAAA,yCAAsB,EAACL,KAAKC;IAC5D,OAAOG,kBAAkB;QAAEJ;QAAKE;IAAkB;AACpD;AAEA;;;CAGC,GACD,SAASE,kBAAkBE,MAG1B;IACC,MAAM,EAAEN,GAAG,EAAEE,iBAAiB,EAAE,GAAGI;IACnC,MAAMC,eAA6B,CAAC;IAEpC,IAAIL,mBAAmBM,QAAQ;QAC7B,KAAK,MAAMC,OAAOP,kBAAmB;YACnCK,YAAY,CAACE,IAAIC,IAAI,CAAC,GAAGD,IAAIE,WAAW;QAC1C;IACF,OAAO;QACL,MAAMC,cAAcC,IAAAA,sBAAe,EAACb;QACpC,MAAMc,WAAWF,eAAeG,IAAAA,8BAAc,EAACH;QAC/C,IAAIE,UAAU;YACZP,YAAY,CAACO,SAASJ,IAAI,CAAC,GAAGI;QAChC;IACF;IAEA,OAAOP;AACT"}
@@ -1,4 +1,4 @@
1
- import { GitCommonOptions } from "./types";
1
+ import { type GitCommonOptions } from "./types.js";
2
2
  /**
3
3
  * Get the value of a git config key. Returns null if it's not set.
4
4
  * (Note: setting `throwOnError: true` will cause it to fail if the key is unset.)