workspace-tools 0.16.2 → 0.18.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.
Files changed (48) hide show
  1. package/CHANGELOG.json +76 -1
  2. package/CHANGELOG.md +34 -2
  3. package/README.md +4 -3
  4. package/beachball.config.js +9 -0
  5. package/lib/__tests__/dependencies.test.js +6 -6
  6. package/lib/__tests__/getChangedPackages.test.js +31 -31
  7. package/lib/__tests__/getDefaultRemote.test.js +6 -6
  8. package/lib/__tests__/getInitDefaultBranch.test.js +6 -6
  9. package/lib/__tests__/getScopedPackages.test.js +9 -9
  10. package/lib/__tests__/getWorkspaceRoot.test.js +11 -11
  11. package/lib/__tests__/getWorkspaces.test.js +15 -15
  12. package/lib/__tests__/lockfile.test.js +28 -11
  13. package/lib/__tests__/queryLockFile.test.d.ts +1 -0
  14. package/lib/__tests__/queryLockFile.test.js +43 -0
  15. package/lib/dependencies.js +1 -0
  16. package/lib/getPackageInfos.js +10 -4
  17. package/lib/getPackagePaths.js +19 -18
  18. package/lib/git.js +30 -23
  19. package/lib/graph.js +2 -1
  20. package/lib/helpers/setupFixture.js +10 -10
  21. package/lib/index.js +28 -19
  22. package/lib/infoFromPackageJson.js +1 -0
  23. package/lib/lockfile/index.d.ts +1 -1
  24. package/lib/lockfile/index.js +54 -15
  25. package/lib/lockfile/nameAtVersion.js +1 -0
  26. package/lib/lockfile/parseNpmLock.d.ts +2 -0
  27. package/lib/lockfile/parseNpmLock.js +22 -0
  28. package/lib/lockfile/parsePnpmLock.js +2 -1
  29. package/lib/lockfile/queryLockFile.js +2 -1
  30. package/lib/lockfile/types.d.ts +31 -0
  31. package/lib/paths.js +1 -0
  32. package/lib/scope.js +3 -2
  33. package/lib/workspaces/findWorkspacePath.js +1 -0
  34. package/lib/workspaces/getChangedPackages.js +8 -7
  35. package/lib/workspaces/getWorkspacePackageInfo.js +1 -0
  36. package/lib/workspaces/getWorkspaceRoot.js +16 -17
  37. package/lib/workspaces/getWorkspaces.js +16 -17
  38. package/lib/workspaces/implementations/index.d.ts +9 -1
  39. package/lib/workspaces/implementations/index.js +48 -20
  40. package/lib/workspaces/implementations/lerna.js +3 -2
  41. package/lib/workspaces/implementations/npm.js +4 -3
  42. package/lib/workspaces/implementations/packageJsonWorkspaces.js +7 -4
  43. package/lib/workspaces/implementations/pnpm.js +5 -4
  44. package/lib/workspaces/implementations/rush.js +2 -1
  45. package/lib/workspaces/implementations/yarn.js +3 -2
  46. package/lib/workspaces/listOfWorkspacePackageNames.js +1 -0
  47. package/lib/workspaces/workspaces.js +2 -1
  48. package/package.json +3 -6
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseNpmLock = void 0;
4
+ const nameAtVersion_1 = require("./nameAtVersion");
5
+ /**
6
+ * formatNpmLock reformats the dependencies object, so the key includes the version, similarly to yarn.lock. For
7
+ * example, `"@microsoft/task-scheduler": { }` will become `"@microsoft/task-scheduler@2.7.1": { }`.
8
+ */
9
+ const formatNpmLock = (previousValue, currentValue) => {
10
+ const [key, dependency] = currentValue;
11
+ previousValue[(0, nameAtVersion_1.nameAtVersion)(key, dependency.version)] = dependency;
12
+ return previousValue;
13
+ };
14
+ const parseNpmLock = (lock) => {
15
+ var _a;
16
+ const dependencies = Object.entries((_a = lock.dependencies) !== null && _a !== void 0 ? _a : {}).reduce(formatNpmLock, {});
17
+ return {
18
+ object: dependencies,
19
+ type: "success",
20
+ };
21
+ };
22
+ exports.parseNpmLock = parseNpmLock;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parsePnpmLock = void 0;
3
4
  const nameAtVersion_1 = require("./nameAtVersion");
4
5
  function parsePnpmLock(yaml) {
5
6
  const object = {};
@@ -9,7 +10,7 @@ function parsePnpmLock(yaml) {
9
10
  const specParts = pkgSpec.split(/\//);
10
11
  const name = specParts.length > 3 ? `${specParts[1]}/${specParts[2]}` : specParts[1];
11
12
  const version = specParts.length > 3 ? specParts[3] : specParts[2];
12
- object[nameAtVersion_1.nameAtVersion(name, version)] = {
13
+ object[(0, nameAtVersion_1.nameAtVersion)(name, version)] = {
13
14
  version,
14
15
  dependencies: snapshot.dependencies,
15
16
  };
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.queryLockFile = void 0;
3
4
  const nameAtVersion_1 = require("./nameAtVersion");
4
5
  function queryLockFile(name, versionRange, lock) {
5
- const versionRangeSignature = nameAtVersion_1.nameAtVersion(name, versionRange);
6
+ const versionRangeSignature = (0, nameAtVersion_1.nameAtVersion)(name, versionRange);
6
7
  return lock.object[versionRangeSignature];
7
8
  }
8
9
  exports.queryLockFile = queryLockFile;
@@ -16,3 +16,34 @@ export interface PnpmLockFile {
16
16
  [name: string]: any;
17
17
  };
18
18
  }
19
+ export interface NpmWorkspacesInfo {
20
+ version: string;
21
+ workspaces: {
22
+ packages: string[];
23
+ };
24
+ }
25
+ export interface NpmSymlinkInfo {
26
+ resolved: string;
27
+ link: boolean;
28
+ integrity?: "sha512" | "sha1";
29
+ dev?: boolean;
30
+ optional?: boolean;
31
+ devOptional?: boolean;
32
+ dependencies?: {
33
+ [key: string]: LockDependency;
34
+ };
35
+ }
36
+ export interface NpmLockFile {
37
+ name: string;
38
+ version: string;
39
+ lockfileVersion?: 1 | 2 | 3;
40
+ requires?: boolean;
41
+ packages?: {
42
+ ""?: NpmWorkspacesInfo;
43
+ } & {
44
+ [key: string]: NpmSymlinkInfo | LockDependency;
45
+ };
46
+ dependencies?: {
47
+ [key: string]: LockDependency;
48
+ };
49
+ }
package/lib/paths.js CHANGED
@@ -3,6 +3,7 @@ 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.isChildOf = exports.getChangePath = exports.findPackageRoot = exports.findGitRoot = exports.searchUp = void 0;
6
7
  const path_1 = __importDefault(require("path"));
7
8
  const fs_1 = __importDefault(require("fs"));
8
9
  /**
package/lib/scope.js CHANGED
@@ -3,6 +3,7 @@ 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.getScopedPackages = void 0;
6
7
  const multimatch_1 = __importDefault(require("multimatch"));
7
8
  /**
8
9
  * Searches all package names based on "scoping" (i.e. "scope" in the sense of inclusion)
@@ -18,7 +19,7 @@ function getScopedPackages(search, packages) {
18
19
  // perform a package-scoped search (e.g. search is @scope/foo*)
19
20
  const scopedSearch = search.filter((needle) => needle.startsWith("@") || needle.startsWith("!@"));
20
21
  if (scopedSearch.length > 0) {
21
- const matched = multimatch_1.default(packageNames, scopedSearch);
22
+ const matched = (0, multimatch_1.default)(packageNames, scopedSearch);
22
23
  for (const pkg of matched) {
23
24
  results.add(pkg);
24
25
  }
@@ -28,7 +29,7 @@ function getScopedPackages(search, packages) {
28
29
  if (unscopedSearch.length > 0) {
29
30
  // only generate the bare package map if there ARE unscoped searches
30
31
  const barePackageMap = generateBarePackageMap(packageNames);
31
- let matched = multimatch_1.default(Object.keys(barePackageMap), unscopedSearch);
32
+ let matched = (0, multimatch_1.default)(Object.keys(barePackageMap), unscopedSearch);
32
33
  for (const bare of matched) {
33
34
  for (const pkg of barePackageMap[bare]) {
34
35
  results.add(pkg);
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findWorkspacePath = void 0;
3
4
  function findWorkspacePath(workspaces, packageName) {
4
5
  const workspace = workspaces.find(({ name }) => name === packageName);
5
6
  if (workspace) {
@@ -3,6 +3,7 @@ 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.getChangedPackages = void 0;
6
7
  const git_1 = require("../git");
7
8
  const getWorkspaces_1 = require("./getWorkspaces");
8
9
  const multimatch_1 = __importDefault(require("multimatch"));
@@ -25,17 +26,17 @@ const path_1 = __importDefault(require("path"));
25
26
  * @returns string[] of package names that have changed
26
27
  */
27
28
  function getChangedPackages(cwd, target, ignoreGlobs = []) {
28
- const workspaceInfo = getWorkspaces_1.getWorkspaces(cwd);
29
- target = target || git_1.getDefaultRemoteBranch(undefined, cwd);
29
+ const workspaceInfo = (0, getWorkspaces_1.getWorkspaces)(cwd);
30
+ target = target || (0, git_1.getDefaultRemoteBranch)(undefined, cwd);
30
31
  let changes = [
31
32
  ...new Set([
32
- ...(git_1.getUntrackedChanges(cwd) || []),
33
- ...(git_1.getUnstagedChanges(cwd) || []),
34
- ...(git_1.getBranchChanges(target, cwd) || []),
35
- ...(git_1.getStagedChanges(cwd) || []),
33
+ ...((0, git_1.getUntrackedChanges)(cwd) || []),
34
+ ...((0, git_1.getUnstagedChanges)(cwd) || []),
35
+ ...((0, git_1.getBranchChanges)(target, cwd) || []),
36
+ ...((0, git_1.getStagedChanges)(cwd) || []),
36
37
  ]),
37
38
  ];
38
- const ignoreSet = new Set(multimatch_1.default(changes, ignoreGlobs));
39
+ const ignoreSet = new Set((0, multimatch_1.default)(changes, ignoreGlobs));
39
40
  changes = changes.filter((change) => !ignoreSet.has(change));
40
41
  const changeSet = new Set();
41
42
  for (const change of changes) {
@@ -3,6 +3,7 @@ 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.getWorkspacePackageInfo = void 0;
6
7
  const path_1 = __importDefault(require("path"));
7
8
  const fs_1 = __importDefault(require("fs"));
8
9
  function getWorkspacePackageInfo(workspacePaths) {
@@ -1,25 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getWorkspaceRoot = void 0;
3
4
  const implementations_1 = require("./implementations");
4
- const pnpm_1 = require("./implementations/pnpm");
5
- const yarn_1 = require("./implementations/yarn");
6
- const rush_1 = require("./implementations/rush");
7
- const npm_1 = require("./implementations/npm");
8
- const lerna_1 = require("./implementations/lerna");
9
- const workspaceGetter = {
10
- yarn: yarn_1.getYarnWorkspaceRoot,
11
- pnpm: pnpm_1.getPnpmWorkspaceRoot,
12
- rush: rush_1.getRushWorkspaceRoot,
13
- npm: npm_1.getNpmWorkspaceRoot,
14
- lerna: lerna_1.getLernaWorkspaceRoot,
15
- };
16
- const preferred = process.env
17
- .PREFERRED_WORKSPACE_MANAGER;
5
+ const preferred = process.env.PREFERRED_WORKSPACE_MANAGER;
18
6
  function getWorkspaceRoot(cwd) {
19
- const workspaceImplementation = preferred || implementations_1.getWorkspaceImplementation(cwd);
20
- if (!workspaceImplementation || !workspaceGetter[workspaceImplementation]) {
7
+ const workspaceImplementation = preferred || (0, implementations_1.getWorkspaceImplementation)(cwd);
8
+ if (!workspaceImplementation) {
21
9
  return;
22
10
  }
23
- return workspaceGetter[workspaceImplementation](cwd);
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
+ }
24
23
  }
25
24
  exports.getWorkspaceRoot = getWorkspaceRoot;
@@ -1,25 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getWorkspaces = void 0;
3
4
  const implementations_1 = require("./implementations");
4
- const pnpm_1 = require("./implementations/pnpm");
5
- const yarn_1 = require("./implementations/yarn");
6
- const rush_1 = require("./implementations/rush");
7
- const npm_1 = require("./implementations/npm");
8
- const lerna_1 = require("./implementations/lerna");
9
- const workspaceGetter = {
10
- yarn: yarn_1.getYarnWorkspaces,
11
- pnpm: pnpm_1.getPnpmWorkspaces,
12
- rush: rush_1.getRushWorkspaces,
13
- npm: npm_1.getNpmWorkspaces,
14
- lerna: lerna_1.getLernaWorkspaces,
15
- };
16
- const preferred = process.env
17
- .PREFERRED_WORKSPACE_MANAGER;
5
+ const preferred = process.env.PREFERRED_WORKSPACE_MANAGER;
18
6
  function getWorkspaces(cwd) {
19
- const workspaceImplementation = preferred || implementations_1.getWorkspaceImplementation(cwd);
20
- if (!workspaceImplementation || !workspaceGetter[workspaceImplementation]) {
7
+ const workspaceImplementation = preferred || (0, implementations_1.getWorkspaceImplementation)(cwd);
8
+ if (!workspaceImplementation) {
21
9
  return [];
22
10
  }
23
- return workspaceGetter[workspaceImplementation](cwd);
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
+ }
24
23
  }
25
24
  exports.getWorkspaces = getWorkspaces;
@@ -1,2 +1,10 @@
1
- export declare type WorkspaceImplementations = "yarn" | "pnpm" | "rush" | "npm" | 'lerna';
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): {
7
+ implementation: WorkspaceImplementations | undefined;
8
+ lockFile: string;
9
+ } | undefined;
2
10
  export declare function getWorkspaceImplementation(cwd: string): WorkspaceImplementations | undefined;
@@ -3,29 +3,57 @@ 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.getWorkspaceImplementation = exports.getWorkspaceImplementationAndLockFile = void 0;
6
7
  const find_up_1 = __importDefault(require("find-up"));
7
- function getWorkspaceImplementation(cwd) {
8
- // This needs to come before Yarn and NPM because
9
- // lerna can be used with either package manager
10
- const lernaJsonPath = find_up_1.default.sync("lerna.json", { cwd });
11
- if (lernaJsonPath) {
12
- return "lerna";
13
- }
14
- const yarnLockPath = find_up_1.default.sync("yarn.lock", { cwd });
15
- if (yarnLockPath) {
16
- return "yarn";
17
- }
18
- const pnpmLockPath = find_up_1.default.sync("pnpm-workspace.yaml", { cwd });
19
- if (pnpmLockPath) {
20
- return "pnpm";
8
+ const path_1 = __importDefault(require("path"));
9
+ const cache = {};
10
+ function getWorkspaceImplementationAndLockFile(cwd) {
11
+ if (cache[cwd]) {
12
+ return cache[cwd];
21
13
  }
22
- const rushJsonPath = find_up_1.default.sync("rush.json", { cwd });
23
- if (rushJsonPath) {
24
- return "rush";
14
+ const lockFile = find_up_1.default.sync(["lerna.json", "yarn.lock", "pnpm-workspace.yaml", "rush.json", "package-lock.json"], {
15
+ cwd,
16
+ });
17
+ if (!lockFile) {
18
+ return;
25
19
  }
26
- const npmLockPath = find_up_1.default.sync("package-lock.json", { cwd });
27
- if (npmLockPath) {
28
- return "npm";
20
+ switch (path_1.default.basename(lockFile)) {
21
+ case "lerna.json":
22
+ cache[cwd] = {
23
+ implementation: "lerna",
24
+ lockFile,
25
+ };
26
+ break;
27
+ case "yarn.lock":
28
+ cache[cwd] = {
29
+ implementation: "yarn",
30
+ lockFile,
31
+ };
32
+ break;
33
+ case "pnpm-workspace.yaml":
34
+ cache[cwd] = {
35
+ implementation: "pnpm",
36
+ lockFile,
37
+ };
38
+ break;
39
+ case "rush.json":
40
+ cache[cwd] = {
41
+ implementation: "rush",
42
+ lockFile,
43
+ };
44
+ break;
45
+ case "package-lock.json":
46
+ cache[cwd] = {
47
+ implementation: "npm",
48
+ lockFile,
49
+ };
50
+ break;
29
51
  }
52
+ return cache[cwd];
53
+ }
54
+ exports.getWorkspaceImplementationAndLockFile = getWorkspaceImplementationAndLockFile;
55
+ function getWorkspaceImplementation(cwd) {
56
+ var _a;
57
+ return (_a = getWorkspaceImplementationAndLockFile(cwd)) === null || _a === void 0 ? void 0 : _a.implementation;
30
58
  }
31
59
  exports.getWorkspaceImplementation = getWorkspaceImplementation;
@@ -3,6 +3,7 @@ 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
7
  const find_up_1 = __importDefault(require("find-up"));
7
8
  const fs_1 = __importDefault(require("fs"));
8
9
  const jju_1 = __importDefault(require("jju"));
@@ -22,8 +23,8 @@ function getLernaWorkspaces(cwd) {
22
23
  const lernaWorkspaceRoot = getLernaWorkspaceRoot(cwd);
23
24
  const lernaJsonPath = path_1.default.join(lernaWorkspaceRoot, "lerna.json");
24
25
  const lernaConfig = jju_1.default.parse(fs_1.default.readFileSync(lernaJsonPath, "utf-8"));
25
- const packagePaths = getPackagePaths_1.getPackagePaths(lernaWorkspaceRoot, lernaConfig.packages);
26
- const workspaceInfo = getWorkspacePackageInfo_1.getWorkspacePackageInfo(packagePaths);
26
+ const packagePaths = (0, getPackagePaths_1.getPackagePaths)(lernaWorkspaceRoot, lernaConfig.packages);
27
+ const workspaceInfo = (0, getWorkspacePackageInfo_1.getWorkspacePackageInfo)(packagePaths);
27
28
  return workspaceInfo;
28
29
  }
29
30
  catch (_a) {
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getNpmWorkspaces = exports.getNpmWorkspaceRoot = void 0;
3
4
  const packageJsonWorkspaces_1 = require("./packageJsonWorkspaces");
4
5
  function getNpmWorkspaceRoot(cwd) {
5
- const npmWorkspacesRoot = packageJsonWorkspaces_1.getPackageJsonWorkspaceRoot(cwd);
6
+ const npmWorkspacesRoot = (0, packageJsonWorkspaces_1.getPackageJsonWorkspaceRoot)(cwd);
6
7
  if (!npmWorkspacesRoot) {
7
8
  throw new Error("Could not find NPM workspaces root");
8
9
  }
@@ -10,7 +11,7 @@ function getNpmWorkspaceRoot(cwd) {
10
11
  }
11
12
  exports.getNpmWorkspaceRoot = getNpmWorkspaceRoot;
12
13
  function getNpmWorkspaces(cwd) {
13
- const yarnWorkspacesRoot = getNpmWorkspaceRoot(cwd);
14
- return packageJsonWorkspaces_1.getWorkspaceInfoFromWorkspaceRoot(yarnWorkspacesRoot);
14
+ const npmWorkspacesRoot = getNpmWorkspaceRoot(cwd);
15
+ return (0, packageJsonWorkspaces_1.getWorkspaceInfoFromWorkspaceRoot)(npmWorkspacesRoot);
15
16
  }
16
17
  exports.getNpmWorkspaces = getNpmWorkspaces;
@@ -3,13 +3,16 @@ 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
- const find_yarn_workspace_root_1 = __importDefault(require("find-yarn-workspace-root"));
6
+ exports.getWorkspaceInfoFromWorkspaceRoot = exports.getPackageJsonWorkspaceRoot = void 0;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const path_1 = __importDefault(require("path"));
9
+ const _1 = require(".");
9
10
  const getPackagePaths_1 = require("../../getPackagePaths");
10
11
  const getWorkspacePackageInfo_1 = require("../getWorkspacePackageInfo");
11
12
  function getPackageJsonWorkspaceRoot(cwd) {
12
- const packageJsonWorkspacesRoot = find_yarn_workspace_root_1.default(cwd);
13
+ var _a;
14
+ const lockFile = (_a = (0, _1.getWorkspaceImplementationAndLockFile)(cwd)) === null || _a === void 0 ? void 0 : _a.lockFile;
15
+ const packageJsonWorkspacesRoot = lockFile ? path_1.default.dirname(lockFile) : cwd;
13
16
  return packageJsonWorkspacesRoot;
14
17
  }
15
18
  exports.getPackageJsonWorkspaceRoot = getPackageJsonWorkspaceRoot;
@@ -37,8 +40,8 @@ function getWorkspaceInfoFromWorkspaceRoot(packageJsonWorkspacesRoot) {
37
40
  try {
38
41
  const rootPackageJson = getRootPackageJson(packageJsonWorkspacesRoot);
39
42
  const packages = getPackages(rootPackageJson);
40
- const packagePaths = getPackagePaths_1.getPackagePaths(packageJsonWorkspacesRoot, packages);
41
- const workspaceInfo = getWorkspacePackageInfo_1.getWorkspacePackageInfo(packagePaths);
43
+ const packagePaths = (0, getPackagePaths_1.getPackagePaths)(packageJsonWorkspacesRoot, packages);
44
+ const workspaceInfo = (0, getWorkspacePackageInfo_1.getWorkspacePackageInfo)(packagePaths);
42
45
  return workspaceInfo;
43
46
  }
44
47
  catch (_a) {
@@ -3,9 +3,9 @@ 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.getPnpmWorkspaces = exports.getPnpmWorkspaceRoot = void 0;
6
7
  const path_1 = __importDefault(require("path"));
7
8
  const find_up_1 = __importDefault(require("find-up"));
8
- const read_yaml_file_1 = require("read-yaml-file");
9
9
  const getPackagePaths_1 = require("../../getPackagePaths");
10
10
  const getWorkspacePackageInfo_1 = require("../getWorkspacePackageInfo");
11
11
  function getPnpmWorkspaceRoot(cwd) {
@@ -20,9 +20,10 @@ function getPnpmWorkspaces(cwd) {
20
20
  try {
21
21
  const pnpmWorkspacesRoot = getPnpmWorkspaceRoot(cwd);
22
22
  const pnpmWorkspacesFile = path_1.default.join(pnpmWorkspacesRoot, "pnpm-workspace.yaml");
23
- const pnpmWorkspaces = read_yaml_file_1.sync(pnpmWorkspacesFile);
24
- const packagePaths = getPackagePaths_1.getPackagePaths(pnpmWorkspacesRoot, pnpmWorkspaces.packages);
25
- const workspaceInfo = getWorkspacePackageInfo_1.getWorkspacePackageInfo(packagePaths);
23
+ const readYaml = require("read-yaml-file").sync;
24
+ const pnpmWorkspaces = readYaml(pnpmWorkspacesFile);
25
+ const packagePaths = (0, getPackagePaths_1.getPackagePaths)(pnpmWorkspacesRoot, pnpmWorkspaces.packages);
26
+ const workspaceInfo = (0, getWorkspacePackageInfo_1.getWorkspacePackageInfo)(packagePaths);
26
27
  return workspaceInfo;
27
28
  }
28
29
  catch (_a) {
@@ -3,6 +3,7 @@ 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.getRushWorkspaces = exports.getRushWorkspaceRoot = void 0;
6
7
  const find_up_1 = __importDefault(require("find-up"));
7
8
  const path_1 = __importDefault(require("path"));
8
9
  const jju_1 = __importDefault(require("jju"));
@@ -22,7 +23,7 @@ function getRushWorkspaces(cwd) {
22
23
  const rushJsonPath = path_1.default.join(rushWorkspaceRoot, "rush.json");
23
24
  const rushConfig = jju_1.default.parse(fs_1.default.readFileSync(rushJsonPath, "utf-8"));
24
25
  const root = path_1.default.dirname(rushJsonPath);
25
- return getWorkspacePackageInfo_1.getWorkspacePackageInfo(rushConfig.projects.map((project) => path_1.default.join(root, project.projectFolder)));
26
+ return (0, getWorkspacePackageInfo_1.getWorkspacePackageInfo)(rushConfig.projects.map((project) => path_1.default.join(root, project.projectFolder)));
26
27
  }
27
28
  catch (_a) {
28
29
  return [];
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getYarnWorkspaces = exports.getYarnWorkspaceRoot = void 0;
3
4
  const packageJsonWorkspaces_1 = require("./packageJsonWorkspaces");
4
5
  function getYarnWorkspaceRoot(cwd) {
5
- const yarnWorkspacesRoot = packageJsonWorkspaces_1.getPackageJsonWorkspaceRoot(cwd);
6
+ const yarnWorkspacesRoot = (0, packageJsonWorkspaces_1.getPackageJsonWorkspaceRoot)(cwd);
6
7
  if (!yarnWorkspacesRoot) {
7
8
  throw new Error("Could not find yarn workspaces root");
8
9
  }
@@ -11,6 +12,6 @@ function getYarnWorkspaceRoot(cwd) {
11
12
  exports.getYarnWorkspaceRoot = getYarnWorkspaceRoot;
12
13
  function getYarnWorkspaces(cwd) {
13
14
  const yarnWorkspacesRoot = getYarnWorkspaceRoot(cwd);
14
- return packageJsonWorkspaces_1.getWorkspaceInfoFromWorkspaceRoot(yarnWorkspacesRoot);
15
+ return (0, packageJsonWorkspaces_1.getWorkspaceInfoFromWorkspaceRoot)(yarnWorkspacesRoot);
15
16
  }
16
17
  exports.getYarnWorkspaces = getYarnWorkspaces;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.listOfWorkspacePackageNames = void 0;
3
4
  function listOfWorkspacePackageNames(workspaces) {
4
5
  return workspaces.map(({ name }) => name);
5
6
  }
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports._resetCache = exports.getAllPackageJsonFiles = void 0;
3
4
  const getWorkspaces_1 = require("./getWorkspaces");
4
5
  const cache = new Map();
5
6
  /**
@@ -10,7 +11,7 @@ function getAllPackageJsonFiles(cwd) {
10
11
  if (cache.has(cwd)) {
11
12
  return cache.get(cwd);
12
13
  }
13
- const workspaces = getWorkspaces_1.getWorkspaces(cwd);
14
+ const workspaces = (0, getWorkspaces_1.getWorkspaces)(cwd);
14
15
  const packageJsonFiles = workspaces.map((workspace) => workspace.packageJson.packageJsonPath);
15
16
  cache.set(cwd, packageJsonFiles);
16
17
  return packageJsonFiles;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "workspace-tools",
3
- "version": "0.16.2",
3
+ "version": "0.18.2",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -19,8 +19,6 @@
19
19
  "dependencies": {
20
20
  "@yarnpkg/lockfile": "^1.1.0",
21
21
  "find-up": "^4.1.0",
22
- "find-yarn-workspace-root": "^1.2.1",
23
- "fs-extra": "^9.0.0",
24
22
  "git-url-parse": "^11.1.2",
25
23
  "globby": "^11.0.0",
26
24
  "jju": "^1.4.0",
@@ -28,7 +26,6 @@
28
26
  "read-yaml-file": "^2.0.0"
29
27
  },
30
28
  "devDependencies": {
31
- "@types/fs-extra": "^8.1.0",
32
29
  "@types/git-url-parse": "^9.0.0",
33
30
  "@types/glob": "^7.1.1",
34
31
  "@types/jest": "^25.2.2",
@@ -37,10 +34,10 @@
37
34
  "@types/node": ">=12.0.0",
38
35
  "@types/tmp": "^0.2.0",
39
36
  "@types/yarnpkg__lockfile": "^1.1.3",
40
- "beachball": "^2.2.0",
37
+ "beachball": "^2.17.0",
41
38
  "jest": "^25.0.0",
42
39
  "tmp": "^0.2.1",
43
40
  "ts-jest": "^25.5.1",
44
- "typescript": "3.8.3"
41
+ "typescript": "^4.5.4"
45
42
  }
46
43
  }