workspace-tools 0.31.0 → 0.33.0

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 (67) hide show
  1. package/CHANGELOG.json +63 -1
  2. package/CHANGELOG.md +28 -2
  3. package/README.md +4 -0
  4. package/lib/dependencies/transitiveDeps.js +2 -1
  5. package/lib/dependencies/transitiveDeps.js.map +1 -1
  6. package/lib/getPackagePaths.d.ts +10 -2
  7. package/lib/getPackagePaths.js +32 -33
  8. package/lib/getPackagePaths.js.map +1 -1
  9. package/lib/graph/createDependencyMap.js +2 -1
  10. package/lib/graph/createDependencyMap.js.map +1 -1
  11. package/lib/graph/getPackageDependencies.d.ts +2 -2
  12. package/lib/graph/getPackageDependencies.js +23 -6
  13. package/lib/graph/getPackageDependencies.js.map +1 -1
  14. package/lib/index.d.ts +3 -3
  15. package/lib/index.js +10 -3
  16. package/lib/index.js.map +1 -1
  17. package/lib/lockfile/index.js +1 -1
  18. package/lib/lockfile/index.js.map +1 -1
  19. package/lib/logging.d.ts +5 -0
  20. package/lib/logging.js +15 -0
  21. package/lib/logging.js.map +1 -0
  22. package/lib/paths.js +7 -1
  23. package/lib/paths.js.map +1 -1
  24. package/lib/types/WorkspaceInfo.d.ts +7 -0
  25. package/lib/workspaces/findWorkspacePath.d.ts +7 -0
  26. package/lib/workspaces/findWorkspacePath.js +9 -4
  27. package/lib/workspaces/findWorkspacePath.js.map +1 -1
  28. package/lib/workspaces/getWorkspacePackageInfo.d.ts +22 -2
  29. package/lib/workspaces/getWorkspacePackageInfo.js +43 -22
  30. package/lib/workspaces/getWorkspacePackageInfo.js.map +1 -1
  31. package/lib/workspaces/getWorkspaceRoot.d.ts +8 -1
  32. package/lib/workspaces/getWorkspaceRoot.js +9 -18
  33. package/lib/workspaces/getWorkspaceRoot.js.map +1 -1
  34. package/lib/workspaces/getWorkspaces.d.ts +16 -0
  35. package/lib/workspaces/getWorkspaces.js +25 -28
  36. package/lib/workspaces/getWorkspaces.js.map +1 -1
  37. package/lib/workspaces/implementations/getWorkspaceManagerAndRoot.d.ts +22 -0
  38. package/lib/workspaces/implementations/getWorkspaceManagerAndRoot.js +63 -0
  39. package/lib/workspaces/implementations/getWorkspaceManagerAndRoot.js.map +1 -0
  40. package/lib/workspaces/implementations/getWorkspaceUtilities.d.ts +18 -0
  41. package/lib/workspaces/implementations/getWorkspaceUtilities.js +26 -0
  42. package/lib/workspaces/implementations/getWorkspaceUtilities.js.map +1 -0
  43. package/lib/workspaces/implementations/index.d.ts +2 -14
  44. package/lib/workspaces/implementations/index.js +5 -55
  45. package/lib/workspaces/implementations/index.js.map +1 -1
  46. package/lib/workspaces/implementations/lerna.d.ts +6 -2
  47. package/lib/workspaces/implementations/lerna.js +17 -10
  48. package/lib/workspaces/implementations/lerna.js.map +1 -1
  49. package/lib/workspaces/implementations/npm.d.ts +10 -1
  50. package/lib/workspaces/implementations/npm.js +19 -8
  51. package/lib/workspaces/implementations/npm.js.map +1 -1
  52. package/lib/workspaces/implementations/packageJsonWorkspaces.d.ts +8 -1
  53. package/lib/workspaces/implementations/packageJsonWorkspaces.js +26 -24
  54. package/lib/workspaces/implementations/packageJsonWorkspaces.js.map +1 -1
  55. package/lib/workspaces/implementations/pnpm.d.ts +6 -0
  56. package/lib/workspaces/implementations/pnpm.js +16 -7
  57. package/lib/workspaces/implementations/pnpm.js.map +1 -1
  58. package/lib/workspaces/implementations/rush.d.ts +6 -0
  59. package/lib/workspaces/implementations/rush.js +16 -7
  60. package/lib/workspaces/implementations/rush.js.map +1 -1
  61. package/lib/workspaces/implementations/yarn.d.ts +11 -0
  62. package/lib/workspaces/implementations/yarn.js +20 -7
  63. package/lib/workspaces/implementations/yarn.js.map +1 -1
  64. package/lib/workspaces/workspaces.d.ts +11 -3
  65. package/lib/workspaces/workspaces.js +13 -5
  66. package/lib/workspaces/workspaces.js.map +1 -1
  67. package/package.json +1 -1
@@ -6,42 +6,62 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getWorkspacePackageInfoAsync = exports.getWorkspacePackageInfo = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const fs_1 = __importDefault(require("fs"));
9
- function getWorkspacePackageInfo(workspacePaths) {
10
- if (!workspacePaths) {
9
+ const promises_1 = __importDefault(require("fs/promises"));
10
+ const logging_1 = require("../logging");
11
+ /**
12
+ * Get an array with names, paths, and package.json contents for each of the given package paths
13
+ * within a workspace.
14
+ *
15
+ * This is an internal helper used by `getWorkspaces` implementations for different managers.
16
+ * (See `../getWorkspaces` for why it's named this way.)
17
+ * @param packagePaths Paths to packages within a workspace
18
+ * @returns Array of workspace package infos
19
+ * @internal
20
+ */
21
+ function getWorkspacePackageInfo(packagePaths) {
22
+ if (!packagePaths) {
11
23
  return [];
12
24
  }
13
- return workspacePaths.reduce((returnValue, workspacePath) => {
25
+ return packagePaths.reduce((workspacePkgs, workspacePath) => {
14
26
  let packageJson;
15
27
  const packageJsonPath = path_1.default.join(workspacePath, "package.json");
16
28
  try {
17
29
  packageJson = JSON.parse(fs_1.default.readFileSync(packageJsonPath, "utf-8"));
18
30
  }
19
- catch {
20
- return returnValue;
31
+ catch (err) {
32
+ (0, logging_1.logVerboseWarning)(`Error reading or parsing ${packageJsonPath} while getting workspace package info`, err);
33
+ return workspacePkgs;
21
34
  }
22
- return [
23
- ...returnValue,
24
- {
25
- name: packageJson.name,
26
- path: workspacePath,
27
- packageJson: {
28
- ...packageJson,
29
- packageJsonPath,
30
- },
35
+ workspacePkgs.push({
36
+ name: packageJson.name,
37
+ path: workspacePath,
38
+ packageJson: {
39
+ ...packageJson,
40
+ packageJsonPath,
31
41
  },
32
- ];
42
+ });
43
+ return workspacePkgs;
33
44
  }, []);
34
45
  }
35
46
  exports.getWorkspacePackageInfo = getWorkspacePackageInfo;
36
- async function getWorkspacePackageInfoAsync(workspacePaths) {
37
- if (!workspacePaths) {
47
+ /**
48
+ * Get an array with names, paths, and package.json contents for each of the given package paths
49
+ * within a workspace.
50
+ *
51
+ * This is an internal helper used by `getWorkspaces` implementations for different managers.
52
+ * (See `../getWorkspaces` for why it's named this way.)
53
+ * @param packagePaths Paths to packages within a workspace
54
+ * @returns Array of workspace package infos
55
+ * @internal
56
+ */
57
+ async function getWorkspacePackageInfoAsync(packagePaths) {
58
+ if (!packagePaths) {
38
59
  return [];
39
60
  }
40
- const packageInfoPromises = workspacePaths.map(async (workspacePath) => {
41
- let packageJson;
61
+ const workspacePkgPromises = packagePaths.map(async (workspacePath) => {
42
62
  const packageJsonPath = path_1.default.join(workspacePath, "package.json");
43
63
  try {
44
- packageJson = JSON.parse(fs_1.default.readFileSync(packageJsonPath, "utf-8"));
64
+ const packageJson = JSON.parse(await promises_1.default.readFile(packageJsonPath, "utf-8"));
45
65
  return {
46
66
  name: packageJson.name,
47
67
  path: workspacePath,
@@ -51,11 +71,12 @@ async function getWorkspacePackageInfoAsync(workspacePaths) {
51
71
  },
52
72
  };
53
73
  }
54
- catch {
74
+ catch (err) {
75
+ (0, logging_1.logVerboseWarning)(`Error reading or parsing ${packageJsonPath} while getting workspace package info`, err);
55
76
  return null;
56
77
  }
57
78
  });
58
- return (await Promise.all(packageInfoPromises)).flat().filter(Boolean);
79
+ return (await Promise.all(workspacePkgPromises)).flat().filter(Boolean);
59
80
  }
60
81
  exports.getWorkspacePackageInfoAsync = getWorkspacePackageInfoAsync;
61
82
  //# sourceMappingURL=getWorkspacePackageInfo.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getWorkspacePackageInfo.js","sourceRoot":"","sources":["../../src/workspaces/getWorkspacePackageInfo.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,4CAAoB;AAIpB,SAAgB,uBAAuB,CAAC,cAAwB;IAC9D,IAAI,CAAC,cAAc,EAAE;QACnB,OAAO,EAAE,CAAC;KACX;IAED,OAAO,cAAc,CAAC,MAAM,CAAgB,CAAC,WAAW,EAAE,aAAa,EAAE,EAAE;QACzE,IAAI,WAAwB,CAAC;QAC7B,MAA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MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,kBAAU,CAAC,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC,CAAgB,CAAC;YACnG,OAAO;gBACL,IAAI,EAAE,WAAW,CAAC,IAAI;gBACtB,IAAI,EAAE,aAAa;gBACnB,WAAW,EAAE;oBACX,GAAG,WAAW;oBACd,eAAe;iBAChB;aACF,CAAC;SACH;QAAC,OAAO,GAAG,EAAE;YACZ,IAAA,2BAAiB,EAAC,4BAA4B,eAAe,uCAAuC,EAAE,GAAG,CAAC,CAAC;YAC3G,OAAO,IAAI,CAAC;SACb;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,OAAO,CAAkB,CAAC;AAC3F,CAAC;AAzBD,oEAyBC"}
@@ -1 +1,8 @@
1
- export declare function getWorkspaceRoot(cwd: string): string | undefined;
1
+ import { WorkspaceManager } from "./WorkspaceManager";
2
+ /**
3
+ * Get the root directory of a workspace/monorepo, defined as the directory where the workspace
4
+ * manager config file is located.
5
+ * @param cwd Start searching from here
6
+ * @param preferredManager Search for only this manager's config file
7
+ */
8
+ export declare function getWorkspaceRoot(cwd: string, preferredManager?: WorkspaceManager): string | undefined;
@@ -2,24 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getWorkspaceRoot = void 0;
4
4
  const implementations_1 = require("./implementations");
5
- const preferred = process.env.PREFERRED_WORKSPACE_MANAGER;
6
- function getWorkspaceRoot(cwd) {
7
- const workspaceImplementation = preferred || (0, implementations_1.getWorkspaceImplementation)(cwd);
8
- if (!workspaceImplementation) {
9
- return;
10
- }
11
- switch (workspaceImplementation) {
12
- case "yarn":
13
- return require(`./implementations/yarn`).getYarnWorkspaceRoot(cwd);
14
- case "pnpm":
15
- return require(`./implementations/pnpm`).getPnpmWorkspaceRoot(cwd);
16
- case "rush":
17
- return require(`./implementations/rush`).getRushWorkspaceRoot(cwd);
18
- case "npm":
19
- return require(`./implementations/npm`).getNpmWorkspaceRoot(cwd);
20
- case "lerna":
21
- return require(`./implementations/lerna`).getLernaWorkspaceRoot(cwd);
22
- }
5
+ /**
6
+ * Get the root directory of a workspace/monorepo, defined as the directory where the workspace
7
+ * manager config file is located.
8
+ * @param cwd Start searching from here
9
+ * @param preferredManager Search for only this manager's config file
10
+ */
11
+ function getWorkspaceRoot(cwd, preferredManager) {
12
+ var _a;
13
+ return (_a = (0, implementations_1.getWorkspaceManagerAndRoot)(cwd, undefined, preferredManager)) === null || _a === void 0 ? void 0 : _a.root;
23
14
  }
24
15
  exports.getWorkspaceRoot = getWorkspaceRoot;
25
16
  //# sourceMappingURL=getWorkspaceRoot.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getWorkspaceRoot.js","sourceRoot":"","sources":["../../src/workspaces/getWorkspaceRoot.ts"],"names":[],"mappings":";;;AAAA,uDAA+D;AAI/D,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,2BAAsD,CAAC;AAErF,SAAgB,gBAAgB,CAAC,GAAW;IAC1C,MAAM,uBAAuB,GAAG,SAAS,IAAI,IAAA,4CAA0B,EAAC,GAAG,CAAC,CAAC;IAE7E,IAAI,CAAC,uBAAuB,EAAE;QAC5B,OAAO;KACR;IAED,QAAQ,uBAAuB,EAAE;QAC/B,KAAK,MAAM;YACT,OAAO,OAAO,CAAC,wBAAwB,CAAC,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC;QAErE,KAAK,MAAM;YACT,OAAO,OAAO,CAAC,wBAAwB,CAAC,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC;QAErE,KAAK,MAAM;YACT,OAAO,OAAO,CAAC,wBAAwB,CAAC,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC;QAErE,KAAK,KAAK;YACR,OAAO,OAAO,CAAC,uBAAuB,CAAC,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;QAEnE,KAAK,OAAO;YACV,OAAO,OAAO,CAAC,yBAAyB,CAAC,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAAC;KACxE;AACH,CAAC;AAvBD,4CAuBC"}
1
+ {"version":3,"file":"getWorkspaceRoot.js","sourceRoot":"","sources":["../../src/workspaces/getWorkspaceRoot.ts"],"names":[],"mappings":";;;AACA,uDAA+D;AAE/D;;;;;GAKG;AACH,SAAgB,gBAAgB,CAAC,GAAW,EAAE,gBAAmC;;IAC/E,OAAO,MAAA,IAAA,4CAA0B,EAAC,GAAG,EAAE,SAAS,EAAE,gBAAgB,CAAC,0CAAE,IAAI,CAAC;AAC5E,CAAC;AAFD,4CAEC"}
@@ -1,3 +1,19 @@
1
1
  import { WorkspaceInfo } from "../types/WorkspaceInfo";
2
+ /**
3
+ * Get an array with names, paths, and package.json contents for each package in a workspace.
4
+ * The list of included packages is based on the workspace manager's config file.
5
+ *
6
+ * The method name is somewhat misleading due to the double meaning of "workspace", but it's retained
7
+ * for compatibility. "Workspace" here refers to an individual package, in the sense of the `workspaces`
8
+ * package.json config used by npm/yarn (instead of referring to the entire monorepo).
9
+ */
2
10
  export declare function getWorkspaces(cwd: string): WorkspaceInfo;
11
+ /**
12
+ * Get an array with names, paths, and package.json contents for each package in a workspace.
13
+ * The list of included packages is based on the workspace manager's config file.
14
+ *
15
+ * The method name is somewhat misleading due to the double meaning of "workspace", but it's retained
16
+ * for compatibility. "Workspace" here refers to an individual package, in the sense of the `workspaces`
17
+ * package.json config used by npm/yarn (instead of referring to the entire monorepo).
18
+ */
3
19
  export declare function getWorkspacesAsync(cwd: string): Promise<WorkspaceInfo>;
@@ -2,41 +2,38 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getWorkspacesAsync = exports.getWorkspaces = void 0;
4
4
  const implementations_1 = require("./implementations");
5
- const preferred = process.env.PREFERRED_WORKSPACE_MANAGER;
5
+ /**
6
+ * Get an array with names, paths, and package.json contents for each package in a workspace.
7
+ * The list of included packages is based on the workspace manager's config file.
8
+ *
9
+ * The method name is somewhat misleading due to the double meaning of "workspace", but it's retained
10
+ * for compatibility. "Workspace" here refers to an individual package, in the sense of the `workspaces`
11
+ * package.json config used by npm/yarn (instead of referring to the entire monorepo).
12
+ */
6
13
  function getWorkspaces(cwd) {
7
- const workspaceImplementation = preferred || (0, implementations_1.getWorkspaceImplementation)(cwd);
8
- if (!workspaceImplementation) {
9
- return [];
10
- }
11
- switch (workspaceImplementation) {
12
- case "yarn":
13
- return require(`./implementations/yarn`).getYarnWorkspaces(cwd);
14
- case "pnpm":
15
- return require(`./implementations/pnpm`).getPnpmWorkspaces(cwd);
16
- case "rush":
17
- return require(`./implementations/rush`).getRushWorkspaces(cwd);
18
- case "npm":
19
- return require(`./implementations/npm`).getNpmWorkspaces(cwd);
20
- case "lerna":
21
- return require(`./implementations/lerna`).getLernaWorkspaces(cwd);
22
- }
14
+ const utils = (0, implementations_1.getWorkspaceUtilities)(cwd);
15
+ return (utils === null || utils === void 0 ? void 0 : utils.getWorkspaces(cwd)) || [];
23
16
  }
24
17
  exports.getWorkspaces = getWorkspaces;
18
+ /**
19
+ * Get an array with names, paths, and package.json contents for each package in a workspace.
20
+ * The list of included packages is based on the workspace manager's config file.
21
+ *
22
+ * The method name is somewhat misleading due to the double meaning of "workspace", but it's retained
23
+ * for compatibility. "Workspace" here refers to an individual package, in the sense of the `workspaces`
24
+ * package.json config used by npm/yarn (instead of referring to the entire monorepo).
25
+ */
25
26
  async function getWorkspacesAsync(cwd) {
26
- const workspaceImplementation = preferred || (0, implementations_1.getWorkspaceImplementation)(cwd);
27
- if (!workspaceImplementation) {
27
+ var _a;
28
+ const utils = (0, implementations_1.getWorkspaceUtilities)(cwd);
29
+ if (!utils) {
28
30
  return [];
29
31
  }
30
- switch (workspaceImplementation) {
31
- case "yarn":
32
- return await require(`./implementations/yarn`).getYarnWorkspacesAsync(cwd);
33
- case "npm":
34
- return require(`./implementations/npm`).getNpmWorkspacesAsync(cwd);
35
- case "pnpm":
36
- case "rush":
37
- case "lerna":
38
- throw new Error(`${cwd} is using ${workspaceImplementation} which has not been converted to async yet`);
32
+ if (!utils.getWorkspacesAsync) {
33
+ const managerName = (_a = (0, implementations_1.getWorkspaceManagerAndRoot)(cwd)) === null || _a === void 0 ? void 0 : _a.manager;
34
+ throw new Error(`${cwd} is using ${managerName} which has not been converted to async yet`);
39
35
  }
36
+ return utils.getWorkspacesAsync(cwd);
40
37
  }
41
38
  exports.getWorkspacesAsync = getWorkspacesAsync;
42
39
  //# sourceMappingURL=getWorkspaces.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getWorkspaces.js","sourceRoot":"","sources":["../../src/workspaces/getWorkspaces.ts"],"names":[],"mappings":";;;AAAA,uDAA+D;AAK/D,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,2BAAsD,CAAC;AAErF,SAAgB,aAAa,CAAC,GAAW;IACvC,MAAM,uBAAuB,GAAG,SAAS,IAAI,IAAA,4CAA0B,EAAC,GAAG,CAAC,CAAC;IAE7E,IAAI,CAAC,uBAAuB,EAAE;QAC5B,OAAO,EAAE,CAAC;KACX;IAED,QAAQ,uBAAuB,EAAE;QAC/B,KAAK,MAAM;YACT,OAAO,OAAO,CAAC,wBAAwB,CAAC,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC;QAElE,KAAK,MAAM;YACT,OAAO,OAAO,CAAC,wBAAwB,CAAC,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC;QAElE,KAAK,MAAM;YACT,OAAO,OAAO,CAAC,wBAAwB,CAAC,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC;QAElE,KAAK,KAAK;YACR,OAAO,OAAO,CAAC,uBAAuB,CAAC,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;QAEhE,KAAK,OAAO;YACV,OAAO,OAAO,CAAC,yBAAyB,CAAC,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC;KACrE;AACH,CAA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CAAC;QAC7D,MAAM,IAAI,KAAK,CAAC,GAAG,GAAG,aAAa,WAAW,4CAA4C,CAAC,CAAC;KAC7F;IAED,OAAO,KAAK,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC;AACvC,CAAC;AAbD,gDAaC"}
@@ -0,0 +1,22 @@
1
+ import { WorkspaceManager } from "../WorkspaceManager";
2
+ export interface WorkspaceManagerAndRoot {
3
+ /** Workspace manager name */
4
+ manager: WorkspaceManager;
5
+ /** Workspace root, where the manager configuration file is located */
6
+ root: string;
7
+ }
8
+ /**
9
+ * Get the preferred workspace manager based on `process.env.PREFERRED_WORKSPACE_MANAGER`
10
+ * (if valid).
11
+ */
12
+ export declare function getPreferredWorkspaceManager(): WorkspaceManager | undefined;
13
+ /**
14
+ * Get the workspace manager name and workspace root directory for `cwd`, with caching.
15
+ * Also respects the `process.env.PREFERRED_WORKSPACE_MANAGER` override, provided the relevant
16
+ * manager file exists.
17
+ * @param cwd Directory to search up from
18
+ * @param cache Optional override cache for testing
19
+ * @param preferredManager Optional override manager (if provided, only searches for this manager's file)
20
+ * @returns Workspace manager and root, or undefined if it can't be determined
21
+ */
22
+ export declare function getWorkspaceManagerAndRoot(cwd: string, cache?: Map<string, WorkspaceManagerAndRoot | undefined>, preferredManager?: WorkspaceManager): WorkspaceManagerAndRoot | undefined;
@@ -0,0 +1,63 @@
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.getWorkspaceManagerAndRoot = exports.getPreferredWorkspaceManager = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const paths_1 = require("../../paths");
9
+ const workspaceCache = new Map();
10
+ /**
11
+ * Files indicating the workspace root for each manager.
12
+ *
13
+ * DO NOT REORDER! The order of keys determines the precedence of the files, which is
14
+ * important for cases like lerna where lerna.json and e.g. yarn.lock may both exist.
15
+ */
16
+ const managerFiles = {
17
+ // DO NOT REORDER! (see above)
18
+ lerna: "lerna.json",
19
+ rush: "rush.json",
20
+ yarn: "yarn.lock",
21
+ pnpm: "pnpm-workspace.yaml",
22
+ npm: "package-lock.json",
23
+ };
24
+ /**
25
+ * Get the preferred workspace manager based on `process.env.PREFERRED_WORKSPACE_MANAGER`
26
+ * (if valid).
27
+ */
28
+ function getPreferredWorkspaceManager() {
29
+ const preferred = process.env.PREFERRED_WORKSPACE_MANAGER;
30
+ return preferred && managerFiles[preferred] ? preferred : undefined;
31
+ }
32
+ exports.getPreferredWorkspaceManager = getPreferredWorkspaceManager;
33
+ /**
34
+ * Get the workspace manager name and workspace root directory for `cwd`, with caching.
35
+ * Also respects the `process.env.PREFERRED_WORKSPACE_MANAGER` override, provided the relevant
36
+ * manager file exists.
37
+ * @param cwd Directory to search up from
38
+ * @param cache Optional override cache for testing
39
+ * @param preferredManager Optional override manager (if provided, only searches for this manager's file)
40
+ * @returns Workspace manager and root, or undefined if it can't be determined
41
+ */
42
+ function getWorkspaceManagerAndRoot(cwd, cache, preferredManager) {
43
+ cache = cache || workspaceCache;
44
+ if (cache.has(cwd)) {
45
+ return cache.get(cwd);
46
+ }
47
+ preferredManager = preferredManager || getPreferredWorkspaceManager();
48
+ const managerFile = (0, paths_1.searchUp)((preferredManager && managerFiles[preferredManager]) || Object.values(managerFiles), cwd);
49
+ if (managerFile) {
50
+ const managerFileName = path_1.default.basename(managerFile);
51
+ cache.set(cwd, {
52
+ manager: Object.keys(managerFiles).find((name) => managerFiles[name] === managerFileName),
53
+ root: path_1.default.dirname(managerFile),
54
+ });
55
+ }
56
+ else {
57
+ // Avoid searching again if no file was found
58
+ cache.set(cwd, undefined);
59
+ }
60
+ return cache.get(cwd);
61
+ }
62
+ exports.getWorkspaceManagerAndRoot = getWorkspaceManagerAndRoot;
63
+ //# sourceMappingURL=getWorkspaceManagerAndRoot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getWorkspaceManagerAndRoot.js","sour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D,CAAC,IAAI,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,eAAe,CAChD;YACF,IAAI,EAAE,cAAI,CAAC,OAAO,CAAC,WAAW,CAAC;SAChC,CAAC,CAAC;KACJ;SAAM;QACL,6CAA6C;QAC7C,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;KAC3B;IAED,OAAO,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AACxB,CAAC;AA9BD,gEA8BC"}
@@ -0,0 +1,18 @@
1
+ import { WorkspaceInfo } from "../../types/WorkspaceInfo";
2
+ export interface WorkspaceUtilities {
3
+ /**
4
+ * Get an array with names, paths, and package.json contents for each package in a workspace.
5
+ * (See `../getWorkspaces` for why it's named this way.)
6
+ */
7
+ getWorkspaces: (cwd: string) => WorkspaceInfo;
8
+ /**
9
+ * Get an array with names, paths, and package.json contents for each package in a workspace.
10
+ * (See `../getWorkspaces` for why it's named this way.)
11
+ */
12
+ getWorkspacesAsync?: (cwd: string) => Promise<WorkspaceInfo>;
13
+ }
14
+ /**
15
+ * Get utility implementations for the workspace manager of `cwd`.
16
+ * Returns undefined if the manager can't be determined.
17
+ */
18
+ export declare function getWorkspaceUtilities(cwd: string): WorkspaceUtilities | undefined;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getWorkspaceUtilities = void 0;
4
+ const getWorkspaceManagerAndRoot_1 = require("./getWorkspaceManagerAndRoot");
5
+ /**
6
+ * Get utility implementations for the workspace manager of `cwd`.
7
+ * Returns undefined if the manager can't be determined.
8
+ */
9
+ function getWorkspaceUtilities(cwd) {
10
+ var _a;
11
+ const manager = (_a = (0, getWorkspaceManagerAndRoot_1.getWorkspaceManagerAndRoot)(cwd)) === null || _a === void 0 ? void 0 : _a.manager;
12
+ switch (manager) {
13
+ case "yarn":
14
+ return require("./yarn");
15
+ case "pnpm":
16
+ return require("./pnpm");
17
+ case "rush":
18
+ return require("./rush");
19
+ case "npm":
20
+ return require("./npm");
21
+ case "lerna":
22
+ return require("./lerna");
23
+ }
24
+ }
25
+ exports.getWorkspaceUtilities = getWorkspaceUtilities;
26
+ //# sourceMappingURL=getWorkspaceUtilities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getWorkspaceUtilities.js","sourceRoot":"","sources":["../../../src/workspaces/implementations/getWorkspaceUtilities.ts"],"names":[],"mappings":";;;AACA,6EAA0E;AAqB1E;;;GAGG;AACH,SAAgB,qBAAqB,CAAC,GAAW;;IAC/C,MAAM,OAAO,GAAG,MAAA,IAAA,uDAA0B,EAAC,GAAG,CAAC,0CAAE,OAAO,CAAC;IAEzD,QAAQ,OAAO,EAAE;QACf,KAAK,MAAM;YACT,OAAO,OAAO,CAAC,QAAQ,CAAyB,CAAC;QAEnD,KAAK,MAAM;YACT,OAAO,OAAO,CAAC,QAAQ,CAAyB,CAAC;QAEnD,KAAK,MAAM;YACT,OAAO,OAAO,CAAC,QAAQ,CAAyB,CAAC;QAEnD,KAAK,KAAK;YACR,OAAO,OAAO,CAAC,OAAO,CAAwB,CAAC;QAEjD,KAAK,OAAO;YACV,OAAO,OAAO,CAAC,SAAS,CAA0B,CAAC;KACtD;AACH,CAAC;AAnBD,sDAmBC"}
@@ -1,14 +1,2 @@
1
- export declare type WorkspaceImplementations = "yarn" | "pnpm" | "rush" | "npm" | "lerna";
2
- export interface ImplementationAndLockFile {
3
- implementation: WorkspaceImplementations | undefined;
4
- lockFile: string;
5
- }
6
- export declare function getWorkspaceImplementationAndLockFile(cwd: string, cache?: {
7
- [cwd: string]: ImplementationAndLockFile;
8
- }): {
9
- implementation: WorkspaceImplementations | undefined;
10
- lockFile: string;
11
- } | undefined;
12
- export declare function getWorkspaceImplementation(cwd: string, cache?: {
13
- [cwd: string]: ImplementationAndLockFile;
14
- }): WorkspaceImplementations | undefined;
1
+ export { getWorkspaceManagerAndRoot, WorkspaceManagerAndRoot } from "./getWorkspaceManagerAndRoot";
2
+ export { getWorkspaceUtilities, WorkspaceUtilities } from "./getWorkspaceUtilities";
@@ -1,58 +1,8 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getWorkspaceImplementation = exports.getWorkspaceImplementationAndLockFile = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- const paths_1 = require("../../paths");
9
- const workspaceCache = {};
10
- function getWorkspaceImplementationAndLockFile(cwd, cache = workspaceCache) {
11
- if (cache[cwd]) {
12
- return cache[cwd];
13
- }
14
- const lockFile = (0, paths_1.searchUp)(["lerna.json", "rush.json", "yarn.lock", "pnpm-workspace.yaml", "package-lock.json"], cwd);
15
- if (!lockFile) {
16
- return;
17
- }
18
- switch (path_1.default.basename(lockFile)) {
19
- case "lerna.json":
20
- cache[cwd] = {
21
- implementation: "lerna",
22
- lockFile,
23
- };
24
- break;
25
- case "yarn.lock":
26
- cache[cwd] = {
27
- implementation: "yarn",
28
- lockFile,
29
- };
30
- break;
31
- case "pnpm-workspace.yaml":
32
- cache[cwd] = {
33
- implementation: "pnpm",
34
- lockFile,
35
- };
36
- break;
37
- case "rush.json":
38
- cache[cwd] = {
39
- implementation: "rush",
40
- lockFile,
41
- };
42
- break;
43
- case "package-lock.json":
44
- cache[cwd] = {
45
- implementation: "npm",
46
- lockFile,
47
- };
48
- break;
49
- }
50
- return cache[cwd];
51
- }
52
- exports.getWorkspaceImplementationAndLockFile = getWorkspaceImplementationAndLockFile;
53
- function getWorkspaceImplementation(cwd, cache = workspaceCache) {
54
- var _a;
55
- return (_a = getWorkspaceImplementationAndLockFile(cwd, cache)) === null || _a === void 0 ? void 0 : _a.implementation;
56
- }
57
- exports.getWorkspaceImplementation = getWorkspaceImplementation;
3
+ exports.getWorkspaceUtilities = exports.getWorkspaceManagerAndRoot = void 0;
4
+ var getWorkspaceManagerAndRoot_1 = require("./getWorkspaceManagerAndRoot");
5
+ Object.defineProperty(exports, "getWorkspaceManagerAndRoot", { enumerable: true, get: function () { return getWorkspaceManagerAndRoot_1.getWorkspaceManagerAndRoot; } });
6
+ var getWorkspaceUtilities_1 = require("./getWorkspaceUtilities");
7
+ Object.defineProperty(exports, "getWorkspaceUtilities", { enumerable: true, get: function () { return getWorkspaceUtilities_1.getWorkspaceUtilities; } });
58
8
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/workspaces/implementations/index.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,uCAAuC;AAOvC,MAAM,cAAc,GAAiD,EAAE,CAAC;AAExE,SAAgB,qCAAqC,CACnD,GAAW,EACX,KAAK,GAAG,cAAc;IAEtB,IAAI,KAAK,CAAC,GAAG,CAAC,EAAE;QACd,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC;KACnB;IAED,MAAM,QAAQ,GAAG,IAAA,gBAAQ,EAAC,CAAC,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,qBAAqB,EAAE,mBAAmB,CAAC,EAAE,GAAG,CAAC,CAAC;IAErH,IAAI,CAAC,QAAQ,EAAE;QACb,OAAO;KACR;IAED,QAAQ,cAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE;QAC/B,KAAK,YAAY;YACf,KAAK,CAAC,GAAG,CAAC,GAAG;gBACX,cAAc,EAAE,OAAO;gBACvB,QAAQ;aACT,CAAC;YACF,MAAM;QAER,KAAK,WAAW;YACd,KAAK,CAAC,GAAG,CAAC,GAAG;gBACX,cAAc,EAAE,MAAM;gBACtB,QAAQ;aACT,CAAC;YACF,MAAM;QAER,KAAK,qBAAqB;YACxB,KAAK,CAAC,GAAG,CAAC,GAAG;gBACX,cAAc,EAAE,MAAM;gBACtB,QAAQ;aACT,CAAC;YACF,MAAM;QAER,KAAK,WAAW;YACd,KAAK,CAAC,GAAG,CAAC,GAAG;gBACX,cAAc,EAAE,MAAM;gBACtB,QAAQ;aACT,CAAC;YACF,MAAM;QAER,KAAK,mBAAmB;YACtB,KAAK,CAAC,GAAG,CAAC,GAAG;gBACX,cAAc,EAAE,KAAK;gBACrB,QAAQ;aACT,CAAC;YACF,MAAM;KACT;IAED,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC;AACpB,CAAC;AApDD,sFAoDC;AAED,SAAgB,0BAA0B,CAAC,GAAW,EAAE,KAAK,GAAG,cAAc;;IAC5E,OAAO,MAAA,qCAAqC,CAAC,GAAG,EAAE,KAAK,CAAC,0CAAE,cAAc,CAAC;AAC3E,CAAC;AAFD,gEAEC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/workspaces/implementations/index.ts"],"names":[],"mappings":";;;AAAA,2EAAmG;AAA1F,wIAAA,0BAA0B,OAAA;AACnC,iEAAoF;AAA3E,8HAAA,qBAAqB,OAAA"}
@@ -1,3 +1,7 @@
1
1
  import { WorkspaceInfo } from "../../types/WorkspaceInfo";
2
- export declare function getLernaWorkspaceRoot(cwd: string): string;
3
- export declare function getLernaWorkspaces(cwd: string, ignorePatterns?: string[]): WorkspaceInfo;
2
+ /**
3
+ * Get an array with names, paths, and package.json contents for each package in a lerna workspace.
4
+ * (See `../getWorkspaces` for why it's named this way.)
5
+ */
6
+ export declare function getLernaWorkspaces(cwd: string): WorkspaceInfo;
7
+ export { getLernaWorkspaces as getWorkspaces };
@@ -3,33 +3,40 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getLernaWorkspaces = exports.getLernaWorkspaceRoot = void 0;
6
+ exports.getWorkspaces = exports.getLernaWorkspaces = void 0;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const jju_1 = __importDefault(require("jju"));
9
9
  const path_1 = __importDefault(require("path"));
10
10
  const getPackagePaths_1 = require("../../getPackagePaths");
11
- const paths_1 = require("../../paths");
12
11
  const getWorkspacePackageInfo_1 = require("../getWorkspacePackageInfo");
12
+ const logging_1 = require("../../logging");
13
+ const getWorkspaceManagerAndRoot_1 = require("./getWorkspaceManagerAndRoot");
13
14
  function getLernaWorkspaceRoot(cwd) {
14
- const lernaJsonPath = (0, paths_1.searchUp)("lerna.json", cwd);
15
- if (!lernaJsonPath) {
16
- throw new Error("Could not find lerna workspace root");
15
+ var _a;
16
+ const root = (_a = (0, getWorkspaceManagerAndRoot_1.getWorkspaceManagerAndRoot)(cwd, undefined, "lerna")) === null || _a === void 0 ? void 0 : _a.root;
17
+ if (!root) {
18
+ throw new Error("Could not find lerna workspace root from " + cwd);
17
19
  }
18
- return path_1.default.dirname(lernaJsonPath);
20
+ return root;
19
21
  }
20
- exports.getLernaWorkspaceRoot = getLernaWorkspaceRoot;
21
- function getLernaWorkspaces(cwd, ignorePatterns) {
22
+ /**
23
+ * Get an array with names, paths, and package.json contents for each package in a lerna workspace.
24
+ * (See `../getWorkspaces` for why it's named this way.)
25
+ */
26
+ function getLernaWorkspaces(cwd) {
22
27
  try {
23
28
  const lernaWorkspaceRoot = getLernaWorkspaceRoot(cwd);
24
29
  const lernaJsonPath = path_1.default.join(lernaWorkspaceRoot, "lerna.json");
25
30
  const lernaConfig = jju_1.default.parse(fs_1.default.readFileSync(lernaJsonPath, "utf-8"));
26
- const packagePaths = (0, getPackagePaths_1.getPackagePaths)(lernaWorkspaceRoot, lernaConfig.packages, ignorePatterns);
31
+ const packagePaths = (0, getPackagePaths_1.getPackagePaths)(lernaWorkspaceRoot, lernaConfig.packages);
27
32
  const workspaceInfo = (0, getWorkspacePackageInfo_1.getWorkspacePackageInfo)(packagePaths);
28
33
  return workspaceInfo;
29
34
  }
30
- catch {
35
+ catch (err) {
36
+ (0, logging_1.logVerboseWarning)(`Error getting lerna workspaces for ${cwd}`, err);
31
37
  return [];
32
38
  }
33
39
  }
34
40
  exports.getLernaWorkspaces = getLernaWorkspaces;
41
+ exports.getWorkspaces = getLernaWorkspaces;
35
42
  //# sourceMappingURL=lerna.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"lerna.js","sourceRoot":"","sources":["../../../src/workspaces/implementations/lerna.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,8CAAsB;AACtB,gDAAwB;AACxB,2DAAwD;AACxD,uCAAuC;AAEvC,wEAAqE;AAErE,SAAgB,qBAAqB,CAAC,GAAW;IAC/C,MAAM,aAAa,GAAG,IAAA,gBAAQ,EAAC,YAAY,EAAE,GAAG,CAAC,CAAC;IAElD,IAAI,CAAC,aAAa,EAAE;QAClB,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;KACxD;IAED,OAAO,cAAI,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;AACrC,CAAC;AARD,sDAQC;AAED,SAAgB,kBAAkB,CAAC,GAAW,EAAE,cAAyB;IACvE,IAAI;QACF,MAAM,kBAAkB,GAAG,qBAAqB,CAAC,GAAG,CAAC,CAAC;QACtD,MAAM,aAAa,GAAG,cAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE,YAAY,CAAC,CAAC;QAElE,MAAM,WAAW,GAAG,aAAG,CAAC,KAAK,CAAC,YAAE,CAAC,YAAY,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC,CAAC;QAEvE,MAAM,YAAY,GAAG,IAAA,iCAAe,EAAC,kBAAkB,EAAE,WAAW,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;QAC/F,MAAM,aAAa,GAAG,IAAA,iDAAuB,EAAC,YAAY,CAAC,CAAC;QAC5D,OAAO,aAAa,CAAC;KACtB;IAAC,MAAM;QACN,OAAO,EAAE,CAAC;KACX;AACH,CAAC;AAbD,gDAaC"}
1
+ {"version":3,"file":"lerna.js","sourceRoot":"","sources":["../../../src/workspaces/implementations/lerna.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,8CAAsB;AACtB,gDAAwB;AACxB,2DAAwD;AAExD,wEAAqE;AACrE,2CAAkD;AAClD,6EAA0E;AAE1E,SAAS,qBAAqB,CAAC,GAAW;;IACxC,MAAM,IAAI,GAAG,MAAA,IAAA,uDAA0B,EAAC,GAAG,EAAE,SAAS,EAAE,OAAO,CAAC,0CAAE,IAAI,CAAC;IACvE,IAAI,CAAC,IAAI,EAAE;QACT,MAAM,IAAI,KAAK,CAAC,2CAA2C,GAAG,GAAG,CAAC,CAAC;KACpE;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,SAAgB,kBAAkB,CAAC,GAAW;IAC5C,IAAI;QACF,MAAM,kBAAkB,GAAG,qBAAqB,CAAC,GAAG,CAAC,CAAC;QACtD,MAAM,aAAa,GAAG,cAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE,YAAY,CAAC,CAAC;QAElE,MAAM,WAAW,GAAG,aAAG,CAAC,KAAK,CAAC,YAAE,CAAC,YAAY,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC,CAAC;QAEvE,MAAM,YAAY,GAAG,IAAA,iCAAe,EAAC,kBAAkB,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;QAC/E,MAAM,aAAa,GAAG,IAAA,iDAAuB,EAAC,YAAY,CAAC,CAAC;QAC5D,OAAO,aAAa,CAAC;KACtB;IAAC,OAAO,GAAG,EAAE;QACZ,IAAA,2BAAiB,EAAC,sCAAsC,GAAG,EAAE,EAAE,GAAG,CAAC,CAAC;QACpE,OAAO,EAAE,CAAC;KACX;AACH,CAAC;AAdD,gDAcC;AAE8B,2CAAa"}
@@ -1,4 +1,13 @@
1
1
  import { WorkspaceInfo } from "../../types/WorkspaceInfo";
2
- export declare function getNpmWorkspaceRoot(cwd: string): string;
2
+ /**
3
+ * Get an array with names, paths, and package.json contents for each package in an npm workspace.
4
+ * (See `../getWorkspaces` for why it's named this way.)
5
+ */
3
6
  export declare function getNpmWorkspaces(cwd: string): WorkspaceInfo;
7
+ /**
8
+ * Get an array with names, paths, and package.json contents for each package in an npm workspace.
9
+ * (See `../getWorkspaces` for why it's named this way.)
10
+ */
4
11
  export declare function getNpmWorkspacesAsync(cwd: string): Promise<WorkspaceInfo>;
12
+ export { getNpmWorkspaces as getWorkspaces };
13
+ export { getNpmWorkspacesAsync as getWorkspacesAsync };
@@ -1,23 +1,34 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getNpmWorkspacesAsync = exports.getNpmWorkspaces = exports.getNpmWorkspaceRoot = void 0;
3
+ exports.getWorkspacesAsync = exports.getWorkspaces = exports.getNpmWorkspacesAsync = exports.getNpmWorkspaces = void 0;
4
+ const _1 = require(".");
4
5
  const packageJsonWorkspaces_1 = require("./packageJsonWorkspaces");
5
6
  function getNpmWorkspaceRoot(cwd) {
6
- const npmWorkspacesRoot = (0, packageJsonWorkspaces_1.getPackageJsonWorkspaceRoot)(cwd);
7
- if (!npmWorkspacesRoot) {
8
- throw new Error("Could not find NPM workspaces root");
7
+ var _a;
8
+ const root = (_a = (0, _1.getWorkspaceManagerAndRoot)(cwd, undefined, "npm")) === null || _a === void 0 ? void 0 : _a.root;
9
+ if (!root) {
10
+ throw new Error("Could not find npm workspace root from " + cwd);
9
11
  }
10
- return npmWorkspacesRoot;
12
+ return root;
11
13
  }
12
- exports.getNpmWorkspaceRoot = getNpmWorkspaceRoot;
14
+ /**
15
+ * Get an array with names, paths, and package.json contents for each package in an npm workspace.
16
+ * (See `../getWorkspaces` for why it's named this way.)
17
+ */
13
18
  function getNpmWorkspaces(cwd) {
14
19
  const npmWorkspacesRoot = getNpmWorkspaceRoot(cwd);
15
20
  return (0, packageJsonWorkspaces_1.getWorkspaceInfoFromWorkspaceRoot)(npmWorkspacesRoot);
16
21
  }
17
22
  exports.getNpmWorkspaces = getNpmWorkspaces;
18
- async function getNpmWorkspacesAsync(cwd) {
23
+ exports.getWorkspaces = getNpmWorkspaces;
24
+ /**
25
+ * Get an array with names, paths, and package.json contents for each package in an npm workspace.
26
+ * (See `../getWorkspaces` for why it's named this way.)
27
+ */
28
+ function getNpmWorkspacesAsync(cwd) {
19
29
  const npmWorkspacesRoot = getNpmWorkspaceRoot(cwd);
20
- return await (0, packageJsonWorkspaces_1.getWorkspaceInfoFromWorkspaceRootAsync)(npmWorkspacesRoot);
30
+ return (0, packageJsonWorkspaces_1.getWorkspaceInfoFromWorkspaceRootAsync)(npmWorkspacesRoot);
21
31
  }
22
32
  exports.getNpmWorkspacesAsync = getNpmWorkspacesAsync;
33
+ exports.getWorkspacesAsync = getNpmWorkspacesAsync;
23
34
  //# sourceMappingURL=npm.js.map