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.
- package/README.md +39 -1
- package/lib/dependencies/index.d.ts +2 -2
- package/lib/dependencies/index.js +31 -12
- package/lib/dependencies/index.js.map +1 -1
- package/lib/dependencies/transitiveDeps.d.ts +1 -1
- package/lib/dependencies/transitiveDeps.js +59 -38
- package/lib/dependencies/transitiveDeps.js.map +1 -1
- package/lib/getPackageInfo.d.ts +7 -5
- package/lib/getPackageInfo.js +46 -39
- package/lib/getPackageInfo.js.map +1 -1
- package/lib/getPackageInfos.d.ts +31 -8
- package/lib/getPackageInfos.js +41 -41
- package/lib/getPackageInfos.js.map +1 -1
- package/lib/git/config.d.ts +1 -1
- package/lib/git/config.js +15 -12
- package/lib/git/config.js.map +1 -1
- package/lib/git/getDefaultRemote.js +45 -30
- package/lib/git/getDefaultRemote.js.map +1 -1
- package/lib/git/getDefaultRemoteBranch.d.ts +1 -1
- package/lib/git/getDefaultRemoteBranch.js +35 -24
- package/lib/git/getDefaultRemoteBranch.js.map +1 -1
- package/lib/git/getRepositoryName.d.ts +1 -1
- package/lib/git/getRepositoryName.js +17 -19
- package/lib/git/getRepositoryName.js.map +1 -1
- package/lib/git/git.d.ts +2 -5
- package/lib/git/git.js +62 -64
- package/lib/git/git.js.map +1 -1
- package/lib/git/gitUtilities.d.ts +3 -3
- package/lib/git/gitUtilities.js +377 -147
- package/lib/git/gitUtilities.js.map +1 -1
- package/lib/git/index.d.ts +5 -5
- package/lib/git/index.js +50 -28
- package/lib/git/index.js.map +1 -1
- package/lib/git/types.js +4 -3
- package/lib/git/types.js.map +1 -1
- package/lib/graph/createDependencyMap.d.ts +12 -2
- package/lib/graph/createDependencyMap.js +18 -10
- package/lib/graph/createDependencyMap.js.map +1 -1
- package/lib/graph/createPackageGraph.d.ts +10 -6
- package/lib/graph/createPackageGraph.js +58 -42
- package/lib/graph/createPackageGraph.js.map +1 -1
- package/lib/graph/getPackageDependencies.d.ts +2 -2
- package/lib/graph/getPackageDependencies.js +24 -53
- package/lib/graph/getPackageDependencies.js.map +1 -1
- package/lib/graph/index.d.ts +4 -4
- package/lib/graph/index.js +25 -27
- package/lib/graph/index.js.map +1 -1
- package/lib/index.d.ts +29 -27
- package/lib/index.js +154 -75
- package/lib/index.js.map +1 -1
- package/lib/isCachingEnabled.js +17 -6
- package/lib/isCachingEnabled.js.map +1 -1
- package/lib/lockfile/nameAtVersion.js +9 -4
- package/lib/lockfile/nameAtVersion.js.map +1 -1
- package/lib/lockfile/parseBerryLock.d.ts +1 -1
- package/lib/lockfile/parseBerryLock.js +13 -11
- package/lib/lockfile/parseBerryLock.js.map +1 -1
- package/lib/lockfile/parseLockFile.d.ts +2 -0
- package/lib/lockfile/parseLockFile.js +87 -0
- package/lib/lockfile/parseLockFile.js.map +1 -0
- package/lib/lockfile/parseNpmLock.d.ts +1 -1
- package/lib/lockfile/parseNpmLock.js +15 -7
- package/lib/lockfile/parseNpmLock.js.map +1 -1
- package/lib/lockfile/parsePnpmLock.d.ts +1 -1
- package/lib/lockfile/parsePnpmLock.js +14 -9
- package/lib/lockfile/parsePnpmLock.js.map +1 -1
- package/lib/lockfile/queryLockFile.d.ts +1 -1
- package/lib/lockfile/queryLockFile.js +11 -6
- package/lib/lockfile/queryLockFile.js.map +1 -1
- package/lib/lockfile/readYaml.js +17 -9
- package/lib/lockfile/readYaml.js.map +1 -1
- package/lib/lockfile/types.js +3 -2
- package/lib/lockfile/types.js.map +1 -1
- package/lib/logging.js +10 -6
- package/lib/logging.js.map +1 -1
- package/lib/paths.d.ts +4 -1
- package/lib/paths.js +60 -58
- package/lib/paths.js.map +1 -1
- package/lib/scope.js +30 -21
- package/lib/scope.js.map +1 -1
- package/lib/types/Catalogs.js +8 -3
- package/lib/types/Catalogs.js.map +1 -1
- package/lib/types/PackageGraph.d.ts +5 -1
- package/lib/types/PackageGraph.js +4 -3
- package/lib/types/PackageGraph.js.map +1 -1
- package/lib/types/PackageInfo.d.ts +1 -1
- package/lib/types/PackageInfo.js +3 -2
- package/lib/types/PackageInfo.js.map +1 -1
- package/lib/types/WorkspaceInfo.d.ts +3 -5
- package/lib/types/WorkspaceInfo.js +3 -2
- package/lib/types/WorkspaceInfo.js.map +1 -1
- package/lib/types/WorkspaceManager.js +4 -0
- package/lib/types/WorkspaceManager.js.map +1 -0
- package/lib/workspaces/catalogsToYaml.d.ts +1 -1
- package/lib/workspaces/catalogsToYaml.js +12 -10
- package/lib/workspaces/catalogsToYaml.js.map +1 -1
- package/lib/workspaces/findWorkspacePath.d.ts +2 -1
- package/lib/workspaces/findWorkspacePath.js +10 -12
- package/lib/workspaces/findWorkspacePath.js.map +1 -1
- package/lib/workspaces/getAllPackageJsonFiles.d.ts +10 -4
- package/lib/workspaces/getAllPackageJsonFiles.js +32 -22
- package/lib/workspaces/getAllPackageJsonFiles.js.map +1 -1
- package/lib/workspaces/getCatalogVersion.d.ts +1 -1
- package/lib/workspaces/getCatalogVersion.js +19 -32
- package/lib/workspaces/getCatalogVersion.js.map +1 -1
- package/lib/workspaces/getCatalogs.d.ts +8 -2
- package/lib/workspaces/getCatalogs.js +23 -15
- package/lib/workspaces/getCatalogs.js.map +1 -1
- package/lib/workspaces/getChangedPackages.d.ts +1 -1
- package/lib/workspaces/getChangedPackages.js +47 -30
- package/lib/workspaces/getChangedPackages.js.map +1 -1
- package/lib/workspaces/getPackagesByFiles.js +29 -24
- package/lib/workspaces/getPackagesByFiles.js.map +1 -1
- package/lib/workspaces/getWorkspaceInfos.d.ts +36 -0
- package/lib/workspaces/getWorkspaceInfos.js +60 -0
- package/lib/workspaces/getWorkspaceInfos.js.map +1 -0
- package/lib/workspaces/getWorkspaceManagerRoot.d.ts +16 -0
- package/lib/workspaces/getWorkspaceManagerRoot.js +32 -0
- package/lib/workspaces/getWorkspaceManagerRoot.js.map +1 -0
- package/lib/workspaces/getWorkspacePackagePaths.d.ts +17 -2
- package/lib/workspaces/getWorkspacePackagePaths.js +138 -24
- package/lib/workspaces/getWorkspacePackagePaths.js.map +1 -1
- package/lib/workspaces/getWorkspacePatterns.d.ts +11 -0
- package/lib/workspaces/getWorkspacePatterns.js +25 -0
- package/lib/workspaces/getWorkspacePatterns.js.map +1 -0
- package/lib/workspaces/implementations/WorkspaceUtilities.d.ts +27 -0
- package/lib/workspaces/implementations/WorkspaceUtilities.js +4 -0
- package/lib/workspaces/implementations/WorkspaceUtilities.js.map +1 -0
- package/lib/workspaces/implementations/getPackageJsonWorkspacePatterns.d.ts +9 -0
- package/lib/workspaces/implementations/getPackageJsonWorkspacePatterns.js +38 -0
- package/lib/workspaces/implementations/getPackageJsonWorkspacePatterns.js.map +1 -0
- package/lib/workspaces/implementations/getWorkspaceManagerAndRoot.d.ts +19 -5
- package/lib/workspaces/implementations/getWorkspaceManagerAndRoot.js +38 -40
- package/lib/workspaces/implementations/getWorkspaceManagerAndRoot.js.map +1 -1
- package/lib/workspaces/implementations/getWorkspaceUtilities.d.ts +4 -36
- package/lib/workspaces/implementations/getWorkspaceUtilities.js +35 -20
- package/lib/workspaces/implementations/getWorkspaceUtilities.js.map +1 -1
- package/lib/workspaces/implementations/index.d.ts +2 -2
- package/lib/workspaces/implementations/index.js +19 -7
- package/lib/workspaces/implementations/index.js.map +1 -1
- package/lib/workspaces/implementations/lerna.d.ts +2 -20
- package/lib/workspaces/implementations/lerna.js +77 -62
- package/lib/workspaces/implementations/lerna.js.map +1 -1
- package/lib/workspaces/implementations/npm.d.ts +3 -17
- package/lib/workspaces/implementations/npm.js +12 -43
- package/lib/workspaces/implementations/npm.js.map +1 -1
- package/lib/workspaces/implementations/pnpm.d.ts +2 -30
- package/lib/workspaces/implementations/pnpm.js +32 -89
- package/lib/workspaces/implementations/pnpm.js.map +1 -1
- package/lib/workspaces/implementations/rush.d.ts +2 -22
- package/lib/workspaces/implementations/rush.js +26 -69
- package/lib/workspaces/implementations/rush.js.map +1 -1
- package/lib/workspaces/implementations/yarn.d.ts +2 -35
- package/lib/workspaces/implementations/yarn.js +33 -85
- package/lib/workspaces/implementations/yarn.js.map +1 -1
- package/lib/workspaces/wrapWorkspaceUtility.d.ts +31 -0
- package/lib/workspaces/wrapWorkspaceUtility.js +47 -0
- package/lib/workspaces/wrapWorkspaceUtility.js.map +1 -0
- package/package.json +21 -12
- package/lib/getPackagePaths.d.ts +0 -10
- package/lib/getPackagePaths.js +0 -49
- package/lib/getPackagePaths.js.map +0 -1
- package/lib/infoFromPackageJson.d.ts +0 -17
- package/lib/infoFromPackageJson.js +0 -11
- package/lib/infoFromPackageJson.js.map +0 -1
- package/lib/lockfile/index.d.ts +0 -6
- package/lib/lockfile/index.js +0 -105
- package/lib/lockfile/index.js.map +0 -1
- package/lib/workspaces/WorkspaceManager.js +0 -3
- package/lib/workspaces/WorkspaceManager.js.map +0 -1
- package/lib/workspaces/getWorkspacePackageInfo.d.ts +0 -26
- package/lib/workspaces/getWorkspacePackageInfo.js +0 -76
- package/lib/workspaces/getWorkspacePackageInfo.js.map +0 -1
- package/lib/workspaces/getWorkspaceRoot.d.ts +0 -25
- package/lib/workspaces/getWorkspaceRoot.js +0 -35
- package/lib/workspaces/getWorkspaceRoot.js.map +0 -1
- package/lib/workspaces/getWorkspaces.d.ts +0 -20
- package/lib/workspaces/getWorkspaces.js +0 -39
- package/lib/workspaces/getWorkspaces.js.map +0 -1
- package/lib/workspaces/implementations/packageJsonWorkspaces.d.ts +0 -31
- package/lib/workspaces/implementations/packageJsonWorkspaces.js +0 -104
- package/lib/workspaces/implementations/packageJsonWorkspaces.js.map +0 -1
- package/lib/workspaces/listOfWorkspacePackageNames.d.ts +0 -5
- package/lib/workspaces/listOfWorkspacePackageNames.js +0 -11
- package/lib/workspaces/listOfWorkspacePackageNames.js.map +0 -1
- /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", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
Object.defineProperty(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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,"
|
|
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", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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({
|
|
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,
|
|
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 ? [
|
|
19
|
-
|
|
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,
|
|
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([
|
|
53
|
+
edges.push([
|
|
54
|
+
dep,
|
|
55
|
+
pkg
|
|
56
|
+
]);
|
|
31
57
|
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
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 = [
|
|
83
|
+
const pkgQueue = [
|
|
84
|
+
...targets
|
|
85
|
+
];
|
|
62
86
|
const visited = new Set();
|
|
63
|
-
while
|
|
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 [
|
|
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 = [
|
|
104
|
+
const pkgQueue = [
|
|
105
|
+
...targets
|
|
106
|
+
];
|
|
86
107
|
const visited = new Set();
|
|
87
|
-
while
|
|
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 [
|
|
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,"
|
|
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":"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"}
|
package/lib/getPackageInfo.d.ts
CHANGED
|
@@ -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
|
-
*
|
|
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
|
-
*
|
|
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>;
|
package/lib/getPackageInfo.js
CHANGED
|
@@ -1,52 +1,59 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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 =
|
|
29
|
+
const packageJsonPath = _path.default.join(cwd, "package.json");
|
|
19
30
|
try {
|
|
20
|
-
if (!
|
|
21
|
-
(0,
|
|
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(
|
|
25
|
-
return
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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 =
|
|
45
|
+
const packageJsonPath = _path.default.join(cwd, "package.json");
|
|
39
46
|
try {
|
|
40
|
-
if (!
|
|
41
|
-
(0,
|
|
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
|
|
45
|
-
return
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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,"
|
|
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"}
|
package/lib/getPackageInfos.d.ts
CHANGED
|
@@ -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
|
|
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
|
-
*
|
|
13
|
-
*
|
|
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>;
|
package/lib/getPackageInfos.js
CHANGED
|
@@ -1,54 +1,54 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
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
|
-
*
|
|
30
|
-
*
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
40
|
-
|
|
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
|
-
|
|
46
|
-
const rootInfo = (0,
|
|
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,"
|
|
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"}
|
package/lib/git/config.d.ts
CHANGED