workspace-tools 0.41.0 → 0.41.2
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 +1 -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 +1 -1
- package/lib/getPackageInfo.js +46 -40
- package/lib/getPackageInfo.js.map +1 -1
- package/lib/getPackageInfos.d.ts +4 -2
- package/lib/getPackageInfos.js +35 -53
- 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 +2 -2
- package/lib/graph/createDependencyMap.js +18 -18
- package/lib/graph/createDependencyMap.js.map +1 -1
- package/lib/graph/createPackageGraph.d.ts +3 -3
- package/lib/graph/createPackageGraph.js +58 -45
- package/lib/graph/createPackageGraph.js.map +1 -1
- package/lib/graph/getPackageDependencies.d.ts +1 -1
- package/lib/graph/getPackageDependencies.js +17 -17
- 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 -26
- package/lib/index.js +154 -70
- 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 +1 -1
- package/lib/paths.js +59 -59
- 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.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 +1 -1
- package/lib/types/WorkspaceInfo.js +3 -2
- package/lib/types/WorkspaceInfo.js.map +1 -1
- package/lib/types/WorkspaceManager.js +3 -2
- package/lib/types/WorkspaceManager.js.map +1 -1
- 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.js +32 -28
- 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 +2 -2
- package/lib/workspaces/getCatalogs.js +17 -22
- 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 +2 -2
- package/lib/workspaces/getWorkspaceInfos.js +43 -58
- package/lib/workspaces/getWorkspaceInfos.js.map +1 -1
- package/lib/workspaces/getWorkspaceManagerRoot.d.ts +1 -1
- package/lib/workspaces/getWorkspaceManagerRoot.js +16 -13
- package/lib/workspaces/getWorkspaceManagerRoot.js.map +1 -1
- package/lib/workspaces/getWorkspacePackagePaths.d.ts +1 -1
- package/lib/workspaces/getWorkspacePackagePaths.js +86 -72
- package/lib/workspaces/getWorkspacePackagePaths.js.map +1 -1
- package/lib/workspaces/getWorkspacePatterns.d.ts +1 -1
- package/lib/workspaces/getWorkspacePatterns.js +18 -20
- package/lib/workspaces/getWorkspacePatterns.js.map +1 -1
- package/lib/workspaces/implementations/WorkspaceUtilities.d.ts +1 -1
- package/lib/workspaces/implementations/WorkspaceUtilities.js +3 -2
- package/lib/workspaces/implementations/WorkspaceUtilities.js.map +1 -1
- package/lib/workspaces/implementations/getPackageJsonWorkspacePatterns.d.ts +1 -1
- package/lib/workspaces/implementations/getPackageJsonWorkspacePatterns.js +24 -22
- package/lib/workspaces/implementations/getPackageJsonWorkspacePatterns.js.map +1 -1
- package/lib/workspaces/implementations/getWorkspaceManagerAndRoot.d.ts +1 -1
- package/lib/workspaces/implementations/getWorkspaceManagerAndRoot.js +38 -43
- package/lib/workspaces/implementations/getWorkspaceManagerAndRoot.js.map +1 -1
- package/lib/workspaces/implementations/getWorkspaceUtilities.d.ts +2 -2
- package/lib/workspaces/implementations/getWorkspaceUtilities.js +25 -13
- 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 +1 -1
- package/lib/workspaces/implementations/lerna.js +55 -31
- package/lib/workspaces/implementations/lerna.js.map +1 -1
- package/lib/workspaces/implementations/npm.d.ts +1 -1
- package/lib/workspaces/implementations/npm.js +12 -7
- package/lib/workspaces/implementations/npm.js.map +1 -1
- package/lib/workspaces/implementations/pnpm.d.ts +1 -1
- package/lib/workspaces/implementations/pnpm.js +28 -17
- package/lib/workspaces/implementations/pnpm.js.map +1 -1
- package/lib/workspaces/implementations/rush.d.ts +1 -1
- package/lib/workspaces/implementations/rush.js +27 -16
- package/lib/workspaces/implementations/rush.js.map +1 -1
- package/lib/workspaces/implementations/yarn.d.ts +1 -1
- package/lib/workspaces/implementations/yarn.js +34 -26
- package/lib/workspaces/implementations/yarn.js.map +1 -1
- package/lib/workspaces/wrapWorkspaceUtility.d.ts +2 -2
- package/lib/workspaces/wrapWorkspaceUtility.js +25 -27
- package/lib/workspaces/wrapWorkspaceUtility.js.map +1 -1
- package/package.json +21 -12
- 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/tsdoc-metadata.json +0 -11
|
@@ -1,38 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "getPackagesByFiles", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return getPackagesByFiles;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _micromatch = /*#__PURE__*/ _interop_require_default(require("micromatch"));
|
|
12
|
+
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
13
|
+
const _getWorkspaceInfos = require("./getWorkspaceInfos.js");
|
|
14
|
+
function _interop_require_default(obj) {
|
|
15
|
+
return obj && obj.__esModule ? obj : {
|
|
16
|
+
default: obj
|
|
17
|
+
};
|
|
18
|
+
}
|
|
10
19
|
function getPackagesByFiles(cwdOrOptions, files, ignoreGlobs, returnAllPackagesOnNoMatch) {
|
|
11
20
|
let root;
|
|
12
21
|
if (typeof cwdOrOptions === "string") {
|
|
13
22
|
root = cwdOrOptions;
|
|
14
23
|
files = files;
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
24
|
+
} else {
|
|
17
25
|
({ root, files, ignoreGlobs, returnAllPackagesOnNoMatch } = cwdOrOptions);
|
|
18
26
|
}
|
|
19
|
-
const workspaces = (0,
|
|
20
|
-
const ignoreSet = new Set(ignoreGlobs?.length ? (0,
|
|
21
|
-
const filteredFiles = files.filter((change)
|
|
27
|
+
const workspaces = (0, _getWorkspaceInfos.getWorkspaceInfos)(root) || [];
|
|
28
|
+
const ignoreSet = new Set(ignoreGlobs?.length ? (0, _micromatch.default)(files, ignoreGlobs) : []);
|
|
29
|
+
const filteredFiles = files.filter((change)=>!ignoreSet.has(change));
|
|
22
30
|
const packages = new Set();
|
|
23
|
-
for (const file of filteredFiles)
|
|
24
|
-
const candidates = workspaces.filter((pkg)
|
|
31
|
+
for (const file of filteredFiles){
|
|
32
|
+
const candidates = workspaces.filter((pkg)=>file.startsWith(_path.default.relative(root, pkg.path).replace(/\\/g, "/")));
|
|
25
33
|
if (candidates.length) {
|
|
26
|
-
const found = candidates.reduce((
|
|
27
|
-
return found.path.length > item.path.length ? found : item;
|
|
28
|
-
}, candidates[0]);
|
|
34
|
+
const found = candidates.reduce((fnd, item)=>fnd.path.length > item.path.length ? fnd : item, candidates[0]);
|
|
29
35
|
packages.add(found.name);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return workspaces.map((pkg) => pkg.name);
|
|
36
|
+
} else if (returnAllPackagesOnNoMatch) {
|
|
37
|
+
return workspaces.map((pkg)=>pkg.name);
|
|
33
38
|
}
|
|
34
39
|
}
|
|
35
|
-
return [
|
|
40
|
+
return [
|
|
41
|
+
...packages
|
|
42
|
+
];
|
|
36
43
|
}
|
|
37
|
-
exports.getPackagesByFiles = getPackagesByFiles;
|
|
38
|
-
//# sourceMappingURL=getPackagesByFiles.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/workspaces/getPackagesByFiles.ts"],"sourcesContent":["import micromatch from \"micromatch\";\nimport path from \"path\";\nimport { getWorkspaceInfos } from \"./getWorkspaceInfos.js\";\n\ninterface GetPackagesByFilesOptions {\n /** Monorepo root directory */\n root: string;\n /** Files to search for */\n files: string[];\n /** Glob patterns to ignore */\n ignoreGlobs?: string[];\n /** If true, will return all packages if no matches are found for any file */\n returnAllPackagesOnNoMatch?: boolean;\n}\n\n/**\n * Given a list of files, finds all packages names that contain those files\n *\n * @returns Package names that have changed\n */\nexport function getPackagesByFiles(options: GetPackagesByFilesOptions): string[];\n/** @deprecated Use object parameter signature instead */\nexport function getPackagesByFiles(\n root: string,\n files: string[],\n ignoreGlobs?: string[],\n returnAllPackagesOnNoMatch?: boolean\n): string[];\nexport function getPackagesByFiles(\n cwdOrOptions: string | GetPackagesByFilesOptions,\n files?: string[],\n ignoreGlobs?: string[],\n returnAllPackagesOnNoMatch?: boolean\n): string[] {\n let root: string;\n if (typeof cwdOrOptions === \"string\") {\n root = cwdOrOptions;\n files = files!;\n } else {\n ({ root, files, ignoreGlobs, returnAllPackagesOnNoMatch } = cwdOrOptions);\n }\n\n const workspaces = getWorkspaceInfos(root) || [];\n const ignoreSet = new Set(ignoreGlobs?.length ? micromatch(files, ignoreGlobs) : []);\n\n const filteredFiles = files.filter((change) => !ignoreSet.has(change));\n\n const packages = new Set<string>();\n\n for (const file of filteredFiles) {\n const candidates = workspaces.filter((pkg) => file.startsWith(path.relative(root, pkg.path).replace(/\\\\/g, \"/\")));\n\n if (candidates.length) {\n const found = candidates.reduce((fnd, item) => (fnd.path.length > item.path.length ? fnd : item), candidates[0]);\n packages.add(found.name);\n } else if (returnAllPackagesOnNoMatch) {\n return workspaces.map((pkg) => pkg.name);\n }\n }\n\n return [...packages];\n}\n"],"names":["getPackagesByFiles","cwdOrOptions","files","ignoreGlobs","returnAllPackagesOnNoMatch","root","workspaces","getWorkspaceInfos","ignoreSet","Set","length","micromatch","filteredFiles","filter","change","has","packages","file","candidates","pkg","startsWith","path","relative","replace","found","reduce","fnd","item","add","name","map"],"mappings":";;;;+BA4BgBA;;;eAAAA;;;mEA5BO;6DACN;mCACiB;;;;;;AA0B3B,SAASA,mBACdC,YAAgD,EAChDC,KAAgB,EAChBC,WAAsB,EACtBC,0BAAoC;IAEpC,IAAIC;IACJ,IAAI,OAAOJ,iBAAiB,UAAU;QACpCI,OAAOJ;QACPC,QAAQA;IACV,OAAO;QACJ,CAAA,EAAEG,IAAI,EAAEH,KAAK,EAAEC,WAAW,EAAEC,0BAA0B,EAAE,GAAGH,YAAW;IACzE;IAEA,MAAMK,aAAaC,IAAAA,oCAAiB,EAACF,SAAS,EAAE;IAChD,MAAMG,YAAY,IAAIC,IAAIN,aAAaO,SAASC,IAAAA,mBAAU,EAACT,OAAOC,eAAe,EAAE;IAEnF,MAAMS,gBAAgBV,MAAMW,MAAM,CAAC,CAACC,SAAW,CAACN,UAAUO,GAAG,CAACD;IAE9D,MAAME,WAAW,IAAIP;IAErB,KAAK,MAAMQ,QAAQL,cAAe;QAChC,MAAMM,aAAaZ,WAAWO,MAAM,CAAC,CAACM,MAAQF,KAAKG,UAAU,CAACC,aAAI,CAACC,QAAQ,CAACjB,MAAMc,IAAIE,IAAI,EAAEE,OAAO,CAAC,OAAO;QAE3G,IAAIL,WAAWR,MAAM,EAAE;YACrB,MAAMc,QAAQN,WAAWO,MAAM,CAAC,CAACC,KAAKC,OAAUD,IAAIL,IAAI,CAACX,MAAM,GAAGiB,KAAKN,IAAI,CAACX,MAAM,GAAGgB,MAAMC,MAAOT,UAAU,CAAC,EAAE;YAC/GF,SAASY,GAAG,CAACJ,MAAMK,IAAI;QACzB,OAAO,IAAIzB,4BAA4B;YACrC,OAAOE,WAAWwB,GAAG,CAAC,CAACX,MAAQA,IAAIU,IAAI;QACzC;IACF;IAEA,OAAO;WAAIb;KAAS;AACtB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { WorkspaceInfos } from "../types/WorkspaceInfo";
|
|
2
|
-
import type { WorkspaceManager } from "../types/WorkspaceManager";
|
|
1
|
+
import type { WorkspaceInfos } from "../types/WorkspaceInfo.js";
|
|
2
|
+
import type { WorkspaceManager } from "../types/WorkspaceManager.js";
|
|
3
3
|
/**
|
|
4
4
|
* Get an array with names, paths, and package.json contents for each package ("workspace" in
|
|
5
5
|
* npm/yarn/pnpm terms) within a monorepo. The list of included packages is based on the
|
|
@@ -1,75 +1,60 @@
|
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get getWorkspaceInfos () {
|
|
13
|
+
return getWorkspaceInfos;
|
|
14
|
+
},
|
|
15
|
+
get getWorkspaceInfosAsync () {
|
|
16
|
+
return getWorkspaceInfosAsync;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _getPackageInfo = require("../getPackageInfo.js");
|
|
20
|
+
const _getWorkspacePackagePaths = require("./getWorkspacePackagePaths.js");
|
|
21
|
+
const _wrapWorkspaceUtility = require("./wrapWorkspaceUtility.js");
|
|
22
22
|
function getWorkspaceInfos(cwd, managerOverride) {
|
|
23
|
-
return (0,
|
|
23
|
+
return (0, _wrapWorkspaceUtility.wrapWorkspaceUtility)({
|
|
24
24
|
cwd,
|
|
25
25
|
managerOverride,
|
|
26
26
|
description: "workspace package infos",
|
|
27
|
-
impl: ({ manager })
|
|
28
|
-
return (0,
|
|
29
|
-
?.map((packagePath) => {
|
|
27
|
+
impl: ({ manager })=>{
|
|
28
|
+
return (0, _getWorkspacePackagePaths.getWorkspacePackagePaths)(cwd, manager)?.map((packagePath)=>{
|
|
30
29
|
// getPackageInfo logs a warning if it can't be read
|
|
31
|
-
const packageJson = (0,
|
|
32
|
-
return packageJson && {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
const packageJson = (0, _getPackageInfo.getPackageInfo)(packagePath);
|
|
31
|
+
return packageJson && {
|
|
32
|
+
name: packageJson.name,
|
|
33
|
+
path: packagePath,
|
|
34
|
+
packageJson
|
|
35
|
+
};
|
|
36
|
+
}).filter(Boolean);
|
|
37
|
+
}
|
|
36
38
|
});
|
|
37
39
|
}
|
|
38
|
-
exports.getWorkspaceInfos = getWorkspaceInfos;
|
|
39
|
-
/**
|
|
40
|
-
* Get an array with names, paths, and package.json contents for each package ("workspace" in
|
|
41
|
-
* npm/yarn/pnpm terms) within a monorepo. The list of included packages is based on the
|
|
42
|
-
* workspace/monorepo manager's config file.
|
|
43
|
-
*
|
|
44
|
-
* Notes:
|
|
45
|
-
* - **WARNING**: As of writing, this will start promises to read all package.json files in
|
|
46
|
-
* parallel, without direct concurrency control.
|
|
47
|
-
* - The workspace manager, root, and list of package paths for `cwd` are cached internally,
|
|
48
|
-
* but the package contents are not.
|
|
49
|
-
* - To get an object with package names as keys, use `getPackageInfosAsync` instead.
|
|
50
|
-
*
|
|
51
|
-
* @param managerOverride Workspace/monorepo manager to use instead of auto-detecting
|
|
52
|
-
*
|
|
53
|
-
* @returns Array of workspace package infos, or undefined if not found (not a monorepo)
|
|
54
|
-
* or there's any issue. (Logs verbose warnings instead of throwing on error.)
|
|
55
|
-
*/
|
|
56
40
|
async function getWorkspaceInfosAsync(cwd, managerOverride) {
|
|
57
|
-
return (0,
|
|
41
|
+
return (0, _wrapWorkspaceUtility.wrapAsyncWorkspaceUtility)({
|
|
58
42
|
cwd,
|
|
59
43
|
managerOverride,
|
|
60
44
|
description: "workspace package infos",
|
|
61
|
-
impl: async ({ manager })
|
|
62
|
-
const packagePaths = await (0,
|
|
63
|
-
if (!packagePaths)
|
|
64
|
-
|
|
65
|
-
const workspacePkgPromises = packagePaths.map(async (packagePath) => {
|
|
45
|
+
impl: async ({ manager })=>{
|
|
46
|
+
const packagePaths = await (0, _getWorkspacePackagePaths.getWorkspacePackagePathsAsync)(cwd, manager);
|
|
47
|
+
if (!packagePaths) return undefined;
|
|
48
|
+
const workspacePkgPromises = packagePaths.map(async (packagePath)=>{
|
|
66
49
|
// getPackageInfoAsync logs a warning if it can't be read
|
|
67
|
-
const packageJson = await (0,
|
|
68
|
-
return packageJson && {
|
|
50
|
+
const packageJson = await (0, _getPackageInfo.getPackageInfoAsync)(packagePath);
|
|
51
|
+
return packageJson && {
|
|
52
|
+
name: packageJson.name,
|
|
53
|
+
path: packagePath,
|
|
54
|
+
packageJson
|
|
55
|
+
};
|
|
69
56
|
});
|
|
70
57
|
return (await Promise.all(workspacePkgPromises)).filter(Boolean);
|
|
71
|
-
}
|
|
58
|
+
}
|
|
72
59
|
});
|
|
73
60
|
}
|
|
74
|
-
exports.getWorkspaceInfosAsync = getWorkspaceInfosAsync;
|
|
75
|
-
//# sourceMappingURL=getWorkspaceInfos.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/workspaces/getWorkspaceInfos.ts"],"sourcesContent":["import { getPackageInfo, getPackageInfoAsync } from \"../getPackageInfo.js\";\nimport type { WorkspaceInfos, WorkspacePackageInfo } from \"../types/WorkspaceInfo.js\";\nimport type { WorkspaceManager } from \"../types/WorkspaceManager.js\";\nimport { getWorkspacePackagePaths, getWorkspacePackagePathsAsync } from \"./getWorkspacePackagePaths.js\";\nimport { wrapAsyncWorkspaceUtility, wrapWorkspaceUtility } from \"./wrapWorkspaceUtility.js\";\n\n/**\n * Get an array with names, paths, and package.json contents for each package (\"workspace\" in\n * npm/yarn/pnpm terms) within a monorepo. The list of included packages is based on the\n * workspace/monorepo manager's config file.\n *\n * Notes:\n * - The workspace manager, root, and list of package paths for `cwd` are cached internally,\n * but the package contents are not.\n * - To get an object with package names as keys, use `getPackageInfos` instead.\n *\n * @param managerOverride Workspace/monorepo manager to use instead of auto-detecting\n *\n * @returns Array of workspace package infos, or undefined if not found (not a monorepo)\n * or there's any issue. (Logs verbose warnings instead of throwing on error.)\n */\nexport function getWorkspaceInfos(cwd: string, managerOverride?: WorkspaceManager): WorkspaceInfos | undefined {\n return wrapWorkspaceUtility({\n cwd,\n managerOverride,\n description: \"workspace package infos\",\n impl: ({ manager }) => {\n return getWorkspacePackagePaths(cwd, manager)\n ?.map<WorkspacePackageInfo | undefined>((packagePath) => {\n // getPackageInfo logs a warning if it can't be read\n const packageJson = getPackageInfo(packagePath);\n return packageJson && { name: packageJson.name, path: packagePath, packageJson };\n })\n .filter(Boolean) as WorkspaceInfos | undefined;\n },\n });\n}\n\n/**\n * Get an array with names, paths, and package.json contents for each package (\"workspace\" in\n * npm/yarn/pnpm terms) within a monorepo. The list of included packages is based on the\n * workspace/monorepo manager's config file.\n *\n * Notes:\n * - **WARNING**: As of writing, this will start promises to read all package.json files in\n * parallel, without direct concurrency control.\n * - The workspace manager, root, and list of package paths for `cwd` are cached internally,\n * but the package contents are not.\n * - To get an object with package names as keys, use `getPackageInfosAsync` instead.\n *\n * @param managerOverride Workspace/monorepo manager to use instead of auto-detecting\n *\n * @returns Array of workspace package infos, or undefined if not found (not a monorepo)\n * or there's any issue. (Logs verbose warnings instead of throwing on error.)\n */\nexport async function getWorkspaceInfosAsync(\n cwd: string,\n managerOverride?: WorkspaceManager\n): Promise<WorkspaceInfos | undefined> {\n return wrapAsyncWorkspaceUtility({\n cwd,\n managerOverride,\n description: \"workspace package infos\",\n impl: async ({ manager }) => {\n const packagePaths = await getWorkspacePackagePathsAsync(cwd, manager);\n if (!packagePaths) return undefined;\n\n const workspacePkgPromises = packagePaths.map<Promise<WorkspacePackageInfo | undefined>>(async (packagePath) => {\n // getPackageInfoAsync logs a warning if it can't be read\n const packageJson = await getPackageInfoAsync(packagePath);\n return packageJson && { name: packageJson.name, path: packagePath, packageJson };\n });\n\n return (await Promise.all(workspacePkgPromises)).filter(Boolean) as WorkspaceInfos;\n },\n });\n}\n"],"names":["getWorkspaceInfos","getWorkspaceInfosAsync","cwd","managerOverride","wrapWorkspaceUtility","description","impl","manager","getWorkspacePackagePaths","map","packagePath","packageJson","getPackageInfo","name","path","filter","Boolean","wrapAsyncWorkspaceUtility","packagePaths","getWorkspacePackagePathsAsync","undefined","workspacePkgPromises","getPackageInfoAsync","Promise","all"],"mappings":";;;;;;;;;;;QAqBgBA;eAAAA;;QAkCMC;eAAAA;;;gCAvD8B;0CAGoB;sCACR;AAiBzD,SAASD,kBAAkBE,GAAW,EAAEC,eAAkC;IAC/E,OAAOC,IAAAA,0CAAoB,EAAC;QAC1BF;QACAC;QACAE,aAAa;QACbC,MAAM,CAAC,EAAEC,OAAO,EAAE;YAChB,OAAOC,IAAAA,kDAAwB,EAACN,KAAKK,UACjCE,IAAsC,CAACC;gBACvC,oDAAoD;gBACpD,MAAMC,cAAcC,IAAAA,8BAAc,EAACF;gBACnC,OAAOC,eAAe;oBAAEE,MAAMF,YAAYE,IAAI;oBAAEC,MAAMJ;oBAAaC;gBAAY;YACjF,GACCI,OAAOC;QACZ;IACF;AACF;AAmBO,eAAef,uBACpBC,GAAW,EACXC,eAAkC;IAElC,OAAOc,IAAAA,+CAAyB,EAAC;QAC/Bf;QACAC;QACAE,aAAa;QACbC,MAAM,OAAO,EAAEC,OAAO,EAAE;YACtB,MAAMW,eAAe,MAAMC,IAAAA,uDAA6B,EAACjB,KAAKK;YAC9D,IAAI,CAACW,cAAc,OAAOE;YAE1B,MAAMC,uBAAuBH,aAAaT,GAAG,CAA4C,OAAOC;gBAC9F,yDAAyD;gBACzD,MAAMC,cAAc,MAAMW,IAAAA,mCAAmB,EAACZ;gBAC9C,OAAOC,eAAe;oBAAEE,MAAMF,YAAYE,IAAI;oBAAEC,MAAMJ;oBAAaC;gBAAY;YACjF;YAEA,OAAO,AAAC,CAAA,MAAMY,QAAQC,GAAG,CAACH,qBAAoB,EAAGN,MAAM,CAACC;QAC1D;IACF;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { WorkspaceManager } from "../types/WorkspaceManager";
|
|
1
|
+
import type { WorkspaceManager } from "../types/WorkspaceManager.js";
|
|
2
2
|
/**
|
|
3
3
|
* Get the root directory of a monorepo, defined as the directory where the workspace/monorepo manager
|
|
4
4
|
* config file is located. (Does not rely in any way on git, and the result is cached by `cwd`.)
|
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "getWorkspaceManagerRoot", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return getWorkspaceManagerRoot;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _logging = require("../logging.js");
|
|
12
|
+
const _index = require("./implementations/index.js");
|
|
6
13
|
function getWorkspaceManagerRoot(cwd, managerOverride, options) {
|
|
7
|
-
const logOrThrow = (message)
|
|
14
|
+
const logOrThrow = (message)=>{
|
|
8
15
|
if (options?.throwOnError) {
|
|
9
16
|
throw new Error(message);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
(0, logging_1.logVerboseWarning)(message);
|
|
17
|
+
} else {
|
|
18
|
+
(0, _logging.logVerboseWarning)(message);
|
|
13
19
|
}
|
|
14
20
|
};
|
|
15
21
|
let root;
|
|
16
22
|
try {
|
|
17
|
-
root = (0,
|
|
18
|
-
}
|
|
19
|
-
catch (err) {
|
|
23
|
+
root = (0, _index.getWorkspaceManagerAndRoot)(cwd, undefined, managerOverride)?.root;
|
|
24
|
+
} catch (err) {
|
|
20
25
|
logOrThrow(`Error getting ${managerOverride || "workspace/monorepo manager"} root from ${cwd}: ${err}`);
|
|
21
26
|
return;
|
|
22
27
|
}
|
|
@@ -25,5 +30,3 @@ function getWorkspaceManagerRoot(cwd, managerOverride, options) {
|
|
|
25
30
|
}
|
|
26
31
|
return root;
|
|
27
32
|
}
|
|
28
|
-
exports.getWorkspaceManagerRoot = getWorkspaceManagerRoot;
|
|
29
|
-
//# sourceMappingURL=getWorkspaceManagerRoot.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/workspaces/getWorkspaceManagerRoot.ts"],"sourcesContent":["import { logVerboseWarning } from \"../logging.js\";\nimport { getWorkspaceManagerAndRoot } from \"./implementations/index.js\";\nimport type { WorkspaceManager } from \"../types/WorkspaceManager.js\";\n\n/**\n * Get the root directory of a monorepo, defined as the directory where the workspace/monorepo manager\n * config file is located. (Does not rely in any way on git, and the result is cached by `cwd`.)\n *\n * @param cwd Start searching from here\n * @param managerOverride Search for only this manager's config file\n *\n * @returns Workspace manager root directory. Returns undefined (and verbose logs) on error or if\n * not found, unless `throwOnError` is set.\n */\nexport function getWorkspaceManagerRoot(cwd: string, managerOverride?: WorkspaceManager): string | undefined;\nexport function getWorkspaceManagerRoot(\n cwd: string,\n managerOverride: WorkspaceManager | undefined,\n options?: {\n /** Throw if there's an error or if the root is not found */\n throwOnError: true;\n }\n): string;\nexport function getWorkspaceManagerRoot(\n cwd: string,\n managerOverride?: WorkspaceManager,\n options?: { throwOnError: true }\n): string | undefined {\n const logOrThrow = (message: string) => {\n if (options?.throwOnError) {\n throw new Error(message);\n } else {\n logVerboseWarning(message);\n }\n };\n\n let root: string | undefined;\n try {\n root = getWorkspaceManagerAndRoot(cwd, undefined, managerOverride)?.root;\n } catch (err) {\n logOrThrow(`Error getting ${managerOverride || \"workspace/monorepo manager\"} root from ${cwd}: ${err}`);\n return;\n }\n\n if (!root) {\n logOrThrow(`Could not find ${managerOverride || \"workspace/monorepo manager\"} root from ${cwd}`);\n }\n return root;\n}\n"],"names":["getWorkspaceManagerRoot","cwd","managerOverride","options","logOrThrow","message","throwOnError","Error","logVerboseWarning","root","getWorkspaceManagerAndRoot","undefined","err"],"mappings":";;;;+BAuBgBA;;;eAAAA;;;yBAvBkB;uBACS;AAsBpC,SAASA,wBACdC,GAAW,EACXC,eAAkC,EAClCC,OAAgC;IAEhC,MAAMC,aAAa,CAACC;QAClB,IAAIF,SAASG,cAAc;YACzB,MAAM,IAAIC,MAAMF;QAClB,OAAO;YACLG,IAAAA,0BAAiB,EAACH;QACpB;IACF;IAEA,IAAII;IACJ,IAAI;QACFA,OAAOC,IAAAA,iCAA0B,EAACT,KAAKU,WAAWT,kBAAkBO;IACtE,EAAE,OAAOG,KAAK;QACZR,WAAW,CAAC,cAAc,EAAEF,mBAAmB,6BAA6B,WAAW,EAAED,IAAI,EAAE,EAAEW,KAAK;QACtG;IACF;IAEA,IAAI,CAACH,MAAM;QACTL,WAAW,CAAC,eAAe,EAAEF,mBAAmB,6BAA6B,WAAW,EAAED,KAAK;IACjG;IACA,OAAOQ;AACT"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { WorkspaceManager } from "../types/WorkspaceManager";
|
|
1
|
+
import type { WorkspaceManager } from "../types/WorkspaceManager.js";
|
|
2
2
|
/**
|
|
3
3
|
* Get a list of package folder paths in the monorepo. The list of included packages is based on
|
|
4
4
|
* the manager's config file and matching package folders (which must contain package.json) on disk.
|
|
@@ -1,130 +1,144 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
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 getWorkspacePackagePaths () {
|
|
13
|
+
return getWorkspacePackagePaths;
|
|
14
|
+
},
|
|
15
|
+
get getWorkspacePackagePathsAsync () {
|
|
16
|
+
return getWorkspacePackagePathsAsync;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _fastglob = /*#__PURE__*/ _interop_require_default(require("fast-glob"));
|
|
20
|
+
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
21
|
+
const _index = require("./implementations/index.js");
|
|
22
|
+
const _isCachingEnabled = require("../isCachingEnabled.js");
|
|
23
|
+
const _wrapWorkspaceUtility = require("./wrapWorkspaceUtility.js");
|
|
24
|
+
function _interop_require_default(obj) {
|
|
25
|
+
return obj && obj.__esModule ? obj : {
|
|
26
|
+
default: obj
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/** Mapping from root path to resolved package paths, or undefined if there was an error */ const packagePathsCache = new Map();
|
|
14
30
|
const globOptions = {
|
|
15
31
|
absolute: true,
|
|
16
|
-
ignore: [
|
|
17
|
-
|
|
32
|
+
ignore: [
|
|
33
|
+
"**/node_modules/**",
|
|
34
|
+
"**/__fixtures__/**"
|
|
35
|
+
],
|
|
36
|
+
stats: false
|
|
18
37
|
};
|
|
19
|
-
/**
|
|
20
|
-
* Get a list of package folder paths in the monorepo. The list of included packages is based on
|
|
21
|
-
* the manager's config file and matching package folders (which must contain package.json) on disk.
|
|
22
|
-
*
|
|
23
|
-
* (The list of package paths is cached per monorepo root if caching is enabled.)
|
|
24
|
-
*
|
|
25
|
-
* @param managerOverride Workspace/monorepo manager to use instead of auto-detecting
|
|
26
|
-
*
|
|
27
|
-
* @returns Package paths, or undefined if there's any issue
|
|
28
|
-
* (logs verbose warnings instead of throwing on error)
|
|
29
|
-
*/
|
|
30
38
|
function getWorkspacePackagePaths(cwd, managerOverride) {
|
|
31
|
-
return (0,
|
|
39
|
+
return (0, _wrapWorkspaceUtility.wrapWorkspaceUtility)({
|
|
32
40
|
cwd,
|
|
33
41
|
managerOverride,
|
|
34
42
|
description: "workspace package paths",
|
|
35
|
-
impl: ({ manager, root })
|
|
36
|
-
const initialResult = getInitialPathsOrGlobs({
|
|
43
|
+
impl: ({ manager, root })=>{
|
|
44
|
+
const initialResult = getInitialPathsOrGlobs({
|
|
45
|
+
manager,
|
|
46
|
+
root
|
|
47
|
+
});
|
|
37
48
|
if (!initialResult || "resolvedPaths" in initialResult) {
|
|
38
49
|
return initialResult?.resolvedPaths;
|
|
39
50
|
}
|
|
40
51
|
try {
|
|
41
|
-
const globResults =
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
52
|
+
const globResults = _fastglob.default.sync(initialResult.globs, {
|
|
53
|
+
cwd: root,
|
|
54
|
+
...globOptions
|
|
55
|
+
});
|
|
56
|
+
return resolveAndCacheGlobResults({
|
|
57
|
+
root,
|
|
58
|
+
globResults
|
|
59
|
+
});
|
|
60
|
+
} catch (err) {
|
|
61
|
+
(0, _isCachingEnabled.isCachingEnabled)() && packagePathsCache.set(root, undefined);
|
|
46
62
|
throw err;
|
|
47
63
|
}
|
|
48
|
-
}
|
|
64
|
+
}
|
|
49
65
|
});
|
|
50
66
|
}
|
|
51
|
-
exports.getWorkspacePackagePaths = getWorkspacePackagePaths;
|
|
52
|
-
/**
|
|
53
|
-
* Get a list of package folder paths in the monorepo. The list of included packages is based on
|
|
54
|
-
* the manager's config file and matching package folders (which must contain package.json) on disk.
|
|
55
|
-
*
|
|
56
|
-
* (The list of package paths is cached per monorepo root if caching is enabled.)
|
|
57
|
-
*
|
|
58
|
-
* @param managerOverride Workspace/monorepo manager to use instead of auto-detecting
|
|
59
|
-
*
|
|
60
|
-
* @returns Package paths, or undefined if there's any issue
|
|
61
|
-
* (logs verbose warnings instead of throwing on error)
|
|
62
|
-
*/
|
|
63
67
|
async function getWorkspacePackagePathsAsync(cwd, managerOverride) {
|
|
64
|
-
return (0,
|
|
68
|
+
return (0, _wrapWorkspaceUtility.wrapAsyncWorkspaceUtility)({
|
|
65
69
|
cwd,
|
|
66
70
|
managerOverride,
|
|
67
71
|
description: "workspace package paths",
|
|
68
|
-
impl: async ({ manager, root })
|
|
69
|
-
const initialResult = getInitialPathsOrGlobs({
|
|
72
|
+
impl: async ({ manager, root })=>{
|
|
73
|
+
const initialResult = getInitialPathsOrGlobs({
|
|
74
|
+
manager,
|
|
75
|
+
root
|
|
76
|
+
});
|
|
70
77
|
if (!initialResult || "resolvedPaths" in initialResult) {
|
|
71
78
|
return initialResult?.resolvedPaths;
|
|
72
79
|
}
|
|
73
80
|
try {
|
|
74
|
-
const globResults = await (0,
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
81
|
+
const globResults = await (0, _fastglob.default)(initialResult.globs, {
|
|
82
|
+
cwd: root,
|
|
83
|
+
...globOptions
|
|
84
|
+
});
|
|
85
|
+
return resolveAndCacheGlobResults({
|
|
86
|
+
root,
|
|
87
|
+
globResults
|
|
88
|
+
});
|
|
89
|
+
} catch (err) {
|
|
90
|
+
(0, _isCachingEnabled.isCachingEnabled)() && packagePathsCache.set(root, undefined);
|
|
79
91
|
throw err;
|
|
80
92
|
}
|
|
81
|
-
}
|
|
93
|
+
}
|
|
82
94
|
});
|
|
83
95
|
}
|
|
84
|
-
exports.getWorkspacePackagePathsAsync = getWorkspacePackagePathsAsync;
|
|
85
96
|
/**
|
|
86
97
|
* Handles the shared synchronous initial logic:
|
|
87
98
|
* - Used the cached result if available
|
|
88
99
|
* - Else, call `getWorkspacePackagePatterns`
|
|
89
100
|
* - If the results are relative paths (not patterns), resolve, cache, and return them
|
|
90
101
|
* - Else, return the prepared globs for sync or async resolution as appropriate.
|
|
91
|
-
*/
|
|
92
|
-
|
|
93
|
-
const canCache = (0, isCachingEnabled_1.isCachingEnabled)();
|
|
102
|
+
*/ function getInitialPathsOrGlobs(params) {
|
|
103
|
+
const canCache = (0, _isCachingEnabled.isCachingEnabled)();
|
|
94
104
|
if (canCache && packagePathsCache.has(params.root)) {
|
|
95
105
|
// Return the cached result, even if it was a failure
|
|
96
106
|
const cachedPaths = packagePathsCache.get(params.root);
|
|
97
|
-
return cachedPaths && {
|
|
107
|
+
return cachedPaths && {
|
|
108
|
+
resolvedPaths: cachedPaths
|
|
109
|
+
};
|
|
98
110
|
}
|
|
99
|
-
const managerUtilities = (0,
|
|
100
|
-
const managerSetting = managerUtilities.getWorkspacePatterns({
|
|
111
|
+
const managerUtilities = (0, _index.getWorkspaceUtilities)(params.manager);
|
|
112
|
+
const managerSetting = managerUtilities.getWorkspacePatterns({
|
|
113
|
+
root: params.root
|
|
114
|
+
});
|
|
101
115
|
if (managerSetting?.type === "pattern") {
|
|
102
116
|
return {
|
|
103
|
-
globs: managerSetting.patterns.map((
|
|
117
|
+
globs: managerSetting.patterns.map((p)=>_path.default.join(p, "package.json").replace(/\\/g, "/"))
|
|
104
118
|
};
|
|
105
119
|
}
|
|
106
120
|
if (managerSetting?.type === "path") {
|
|
107
|
-
const resolvedPaths = managerSetting.patterns.map((p)
|
|
121
|
+
const resolvedPaths = managerSetting.patterns.map((p)=>_path.default.resolve(params.root, p));
|
|
108
122
|
if (canCache) {
|
|
109
123
|
packagePathsCache.set(params.root, resolvedPaths);
|
|
110
124
|
}
|
|
111
|
-
return {
|
|
125
|
+
return {
|
|
126
|
+
resolvedPaths
|
|
127
|
+
};
|
|
112
128
|
}
|
|
113
129
|
return undefined;
|
|
114
130
|
}
|
|
115
131
|
/**
|
|
116
132
|
* Given the results from globbing package.json files, resolve to package folder paths
|
|
117
133
|
* and cache the results.
|
|
118
|
-
*/
|
|
119
|
-
function resolveAndCacheGlobResults(params) {
|
|
134
|
+
*/ function resolveAndCacheGlobResults(params) {
|
|
120
135
|
const { root, globResults } = params;
|
|
121
|
-
const resolvedPaths = globResults.map((packageJsonPath)
|
|
122
|
-
const packagePath =
|
|
123
|
-
return
|
|
136
|
+
const resolvedPaths = globResults.map((packageJsonPath)=>{
|
|
137
|
+
const packagePath = _path.default.dirname(packageJsonPath);
|
|
138
|
+
return _path.default.sep === "/" ? packagePath : packagePath.replace(/\//g, _path.default.sep);
|
|
124
139
|
});
|
|
125
|
-
if ((0,
|
|
140
|
+
if ((0, _isCachingEnabled.isCachingEnabled)()) {
|
|
126
141
|
packagePathsCache.set(root, resolvedPaths);
|
|
127
142
|
}
|
|
128
143
|
return resolvedPaths;
|
|
129
144
|
}
|
|
130
|
-
//# sourceMappingURL=getWorkspacePackagePaths.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/workspaces/getWorkspacePackagePaths.ts"],"sourcesContent":["import glob, { type Options as GlobOptions } from \"fast-glob\";\nimport path from \"path\";\nimport type { WorkspaceManager } from \"../types/WorkspaceManager.js\";\nimport { getWorkspaceUtilities, type WorkspaceManagerAndRoot } from \"./implementations/index.js\";\nimport { isCachingEnabled } from \"../isCachingEnabled.js\";\nimport { wrapWorkspaceUtility, wrapAsyncWorkspaceUtility } from \"./wrapWorkspaceUtility.js\";\n\n/** Mapping from root path to resolved package paths, or undefined if there was an error */\nconst packagePathsCache = new Map<string, string[] | undefined>();\n\nconst globOptions: GlobOptions = {\n absolute: true,\n ignore: [\"**/node_modules/**\", \"**/__fixtures__/**\"],\n stats: false,\n};\n\n/**\n * Get a list of package folder paths in the monorepo. The list of included packages is based on\n * the manager's config file and matching package folders (which must contain package.json) on disk.\n *\n * (The list of package paths is cached per monorepo root if caching is enabled.)\n *\n * @param managerOverride Workspace/monorepo manager to use instead of auto-detecting\n *\n * @returns Package paths, or undefined if there's any issue\n * (logs verbose warnings instead of throwing on error)\n */\nexport function getWorkspacePackagePaths(cwd: string, managerOverride?: WorkspaceManager): string[] | undefined {\n return wrapWorkspaceUtility({\n cwd,\n managerOverride,\n description: \"workspace package paths\",\n impl: ({ manager, root }) => {\n const initialResult = getInitialPathsOrGlobs({ manager, root });\n if (!initialResult || \"resolvedPaths\" in initialResult) {\n return initialResult?.resolvedPaths;\n }\n\n try {\n const globResults = glob.sync(initialResult.globs, { cwd: root, ...globOptions });\n return resolveAndCacheGlobResults({ root, globResults });\n } catch (err) {\n isCachingEnabled() && packagePathsCache.set(root, undefined);\n throw err;\n }\n },\n });\n}\n\n/**\n * Get a list of package folder paths in the monorepo. The list of included packages is based on\n * the manager's config file and matching package folders (which must contain package.json) on disk.\n *\n * (The list of package paths is cached per monorepo root if caching is enabled.)\n *\n * @param managerOverride Workspace/monorepo manager to use instead of auto-detecting\n *\n * @returns Package paths, or undefined if there's any issue\n * (logs verbose warnings instead of throwing on error)\n */\nexport async function getWorkspacePackagePathsAsync(\n cwd: string,\n managerOverride?: WorkspaceManager\n): Promise<string[] | undefined> {\n return wrapAsyncWorkspaceUtility({\n cwd,\n managerOverride,\n description: \"workspace package paths\",\n impl: async ({ manager, root }) => {\n const initialResult = getInitialPathsOrGlobs({ manager, root });\n if (!initialResult || \"resolvedPaths\" in initialResult) {\n return initialResult?.resolvedPaths;\n }\n\n try {\n const globResults = await glob(initialResult.globs, { cwd: root, ...globOptions });\n return resolveAndCacheGlobResults({ root, globResults });\n } catch (err) {\n isCachingEnabled() && packagePathsCache.set(root, undefined);\n throw err;\n }\n },\n });\n}\n\n/**\n * Handles the shared synchronous initial logic:\n * - Used the cached result if available\n * - Else, call `getWorkspacePackagePatterns`\n * - If the results are relative paths (not patterns), resolve, cache, and return them\n * - Else, return the prepared globs for sync or async resolution as appropriate.\n */\nfunction getInitialPathsOrGlobs(\n params: WorkspaceManagerAndRoot\n): { globs: string[] } | { resolvedPaths: string[] } | undefined {\n const canCache = isCachingEnabled();\n if (canCache && packagePathsCache.has(params.root)) {\n // Return the cached result, even if it was a failure\n const cachedPaths = packagePathsCache.get(params.root);\n return cachedPaths && { resolvedPaths: cachedPaths };\n }\n\n const managerUtilities = getWorkspaceUtilities(params.manager);\n const managerSetting = managerUtilities.getWorkspacePatterns({ root: params.root });\n\n if (managerSetting?.type === \"pattern\") {\n return {\n globs: managerSetting.patterns.map((p) => path.join(p, \"package.json\").replace(/\\\\/g, \"/\")),\n };\n }\n\n if (managerSetting?.type === \"path\") {\n const resolvedPaths = managerSetting.patterns.map((p) => path.resolve(params.root, p));\n if (canCache) {\n packagePathsCache.set(params.root, resolvedPaths);\n }\n return { resolvedPaths };\n }\n\n return undefined;\n}\n\n/**\n * Given the results from globbing package.json files, resolve to package folder paths\n * and cache the results.\n */\nfunction resolveAndCacheGlobResults(params: { root: string; globResults: string[] }) {\n const { root, globResults } = params;\n const resolvedPaths = globResults.map((packageJsonPath) => {\n const packagePath = path.dirname(packageJsonPath);\n return path.sep === \"/\" ? packagePath : packagePath.replace(/\\//g, path.sep);\n });\n if (isCachingEnabled()) {\n packagePathsCache.set(root, resolvedPaths);\n }\n return resolvedPaths;\n}\n"],"names":["getWorkspacePackagePaths","getWorkspacePackagePathsAsync","packagePathsCache","Map","globOptions","absolute","ignore","stats","cwd","managerOverride","wrapWorkspaceUtility","description","impl","manager","root","initialResult","getInitialPathsOrGlobs","resolvedPaths","globResults","glob","sync","globs","resolveAndCacheGlobResults","err","isCachingEnabled","set","undefined","wrapAsyncWorkspaceUtility","params","canCache","has","cachedPaths","get","managerUtilities","getWorkspaceUtilities","managerSetting","getWorkspacePatterns","type","patterns","map","p","path","join","replace","resolve","packageJsonPath","packagePath","dirname","sep"],"mappings":";;;;;;;;;;;QA2BgBA;eAAAA;;QAiCMC;eAAAA;;;iEA5D4B;6DACjC;uBAEmD;kCACnC;sCAC+B;;;;;;AAEhE,yFAAyF,GACzF,MAAMC,oBAAoB,IAAIC;AAE9B,MAAMC,cAA2B;IAC/BC,UAAU;IACVC,QAAQ;QAAC;QAAsB;KAAqB;IACpDC,OAAO;AACT;AAaO,SAASP,yBAAyBQ,GAAW,EAAEC,eAAkC;IACtF,OAAOC,IAAAA,0CAAoB,EAAC;QAC1BF;QACAC;QACAE,aAAa;QACbC,MAAM,CAAC,EAAEC,OAAO,EAAEC,IAAI,EAAE;YACtB,MAAMC,gBAAgBC,uBAAuB;gBAAEH;gBAASC;YAAK;YAC7D,IAAI,CAACC,iBAAiB,mBAAmBA,eAAe;gBACtD,OAAOA,eAAeE;YACxB;YAEA,IAAI;gBACF,MAAMC,cAAcC,iBAAI,CAACC,IAAI,CAACL,cAAcM,KAAK,EAAE;oBAAEb,KAAKM;oBAAM,GAAGV,WAAW;gBAAC;gBAC/E,OAAOkB,2BAA2B;oBAAER;oBAAMI;gBAAY;YACxD,EAAE,OAAOK,KAAK;gBACZC,IAAAA,kCAAgB,OAAMtB,kBAAkBuB,GAAG,CAACX,MAAMY;gBAClD,MAAMH;YACR;QACF;IACF;AACF;AAaO,eAAetB,8BACpBO,GAAW,EACXC,eAAkC;IAElC,OAAOkB,IAAAA,+CAAyB,EAAC;QAC/BnB;QACAC;QACAE,aAAa;QACbC,MAAM,OAAO,EAAEC,OAAO,EAAEC,IAAI,EAAE;YAC5B,MAAMC,gBAAgBC,uBAAuB;gBAAEH;gBAASC;YAAK;YAC7D,IAAI,CAACC,iBAAiB,mBAAmBA,eAAe;gBACtD,OAAOA,eAAeE;YACxB;YAEA,IAAI;gBACF,MAAMC,cAAc,MAAMC,IAAAA,iBAAI,EAACJ,cAAcM,KAAK,EAAE;oBAAEb,KAAKM;oBAAM,GAAGV,WAAW;gBAAC;gBAChF,OAAOkB,2BAA2B;oBAAER;oBAAMI;gBAAY;YACxD,EAAE,OAAOK,KAAK;gBACZC,IAAAA,kCAAgB,OAAMtB,kBAAkBuB,GAAG,CAACX,MAAMY;gBAClD,MAAMH;YACR;QACF;IACF;AACF;AAEA;;;;;;CAMC,GACD,SAASP,uBACPY,MAA+B;IAE/B,MAAMC,WAAWL,IAAAA,kCAAgB;IACjC,IAAIK,YAAY3B,kBAAkB4B,GAAG,CAACF,OAAOd,IAAI,GAAG;QAClD,qDAAqD;QACrD,MAAMiB,cAAc7B,kBAAkB8B,GAAG,CAACJ,OAAOd,IAAI;QACrD,OAAOiB,eAAe;YAAEd,eAAec;QAAY;IACrD;IAEA,MAAME,mBAAmBC,IAAAA,4BAAqB,EAACN,OAAOf,OAAO;IAC7D,MAAMsB,iBAAiBF,iBAAiBG,oBAAoB,CAAC;QAAEtB,MAAMc,OAAOd,IAAI;IAAC;IAEjF,IAAIqB,gBAAgBE,SAAS,WAAW;QACtC,OAAO;YACLhB,OAAOc,eAAeG,QAAQ,CAACC,GAAG,CAAC,CAACC,IAAMC,aAAI,CAACC,IAAI,CAACF,GAAG,gBAAgBG,OAAO,CAAC,OAAO;QACxF;IACF;IAEA,IAAIR,gBAAgBE,SAAS,QAAQ;QACnC,MAAMpB,gBAAgBkB,eAAeG,QAAQ,CAACC,GAAG,CAAC,CAACC,IAAMC,aAAI,CAACG,OAAO,CAAChB,OAAOd,IAAI,EAAE0B;QACnF,IAAIX,UAAU;YACZ3B,kBAAkBuB,GAAG,CAACG,OAAOd,IAAI,EAAEG;QACrC;QACA,OAAO;YAAEA;QAAc;IACzB;IAEA,OAAOS;AACT;AAEA;;;CAGC,GACD,SAASJ,2BAA2BM,MAA+C;IACjF,MAAM,EAAEd,IAAI,EAAEI,WAAW,EAAE,GAAGU;IAC9B,MAAMX,gBAAgBC,YAAYqB,GAAG,CAAC,CAACM;QACrC,MAAMC,cAAcL,aAAI,CAACM,OAAO,CAACF;QACjC,OAAOJ,aAAI,CAACO,GAAG,KAAK,MAAMF,cAAcA,YAAYH,OAAO,CAAC,OAAOF,aAAI,CAACO,GAAG;IAC7E;IACA,IAAIxB,IAAAA,kCAAgB,KAAI;QACtBtB,kBAAkBuB,GAAG,CAACX,MAAMG;IAC9B;IACA,OAAOA;AACT"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { WorkspaceManager } from "../types/WorkspaceManager";
|
|
1
|
+
import type { WorkspaceManager } from "../types/WorkspaceManager.js";
|
|
2
2
|
/**
|
|
3
3
|
* Get the original glob patterns from the manager's workspaces config.
|
|
4
4
|
* (Calculation of the workspace manager and root for `cwd` is cached internally.)
|