workspace-tools 0.18.0 → 0.18.3

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 (43) hide show
  1. package/CHANGELOG.json +46 -1
  2. package/CHANGELOG.md +26 -2
  3. package/lib/__tests__/dependencies.test.js +6 -6
  4. package/lib/__tests__/getChangedPackages.test.js +31 -31
  5. package/lib/__tests__/getDefaultRemote.test.js +6 -6
  6. package/lib/__tests__/getInitDefaultBranch.test.js +6 -6
  7. package/lib/__tests__/getScopedPackages.test.js +9 -9
  8. package/lib/__tests__/getWorkspaceRoot.test.js +11 -11
  9. package/lib/__tests__/getWorkspaces.test.js +37 -16
  10. package/lib/__tests__/lockfile.test.js +12 -12
  11. package/lib/__tests__/queryLockFile.test.d.ts +1 -0
  12. package/lib/__tests__/queryLockFile.test.js +43 -0
  13. package/lib/dependencies.js +1 -0
  14. package/lib/getPackageInfos.js +10 -4
  15. package/lib/getPackagePaths.js +1 -0
  16. package/lib/git.js +30 -23
  17. package/lib/graph.js +2 -1
  18. package/lib/helpers/setupFixture.js +8 -5
  19. package/lib/index.js +28 -19
  20. package/lib/infoFromPackageJson.js +1 -0
  21. package/lib/lockfile/index.js +29 -12
  22. package/lib/lockfile/nameAtVersion.js +1 -0
  23. package/lib/lockfile/parseNpmLock.js +17 -4
  24. package/lib/lockfile/parsePnpmLock.js +2 -1
  25. package/lib/lockfile/queryLockFile.js +2 -1
  26. package/lib/paths.js +1 -0
  27. package/lib/scope.js +3 -2
  28. package/lib/workspaces/findWorkspacePath.js +1 -0
  29. package/lib/workspaces/getChangedPackages.js +8 -7
  30. package/lib/workspaces/getWorkspacePackageInfo.js +1 -0
  31. package/lib/workspaces/getWorkspaceRoot.js +2 -1
  32. package/lib/workspaces/getWorkspaces.js +2 -1
  33. package/lib/workspaces/implementations/index.d.ts +6 -2
  34. package/lib/workspaces/implementations/index.js +6 -5
  35. package/lib/workspaces/implementations/lerna.js +3 -2
  36. package/lib/workspaces/implementations/npm.js +3 -2
  37. package/lib/workspaces/implementations/packageJsonWorkspaces.js +4 -3
  38. package/lib/workspaces/implementations/pnpm.js +3 -2
  39. package/lib/workspaces/implementations/rush.js +2 -1
  40. package/lib/workspaces/implementations/yarn.js +3 -2
  41. package/lib/workspaces/listOfWorkspacePackageNames.js +1 -0
  42. package/lib/workspaces/workspaces.js +2 -1
  43. package/package.json +2 -2
@@ -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,9 +1,10 @@
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
5
  const preferred = process.env.PREFERRED_WORKSPACE_MANAGER;
5
6
  function getWorkspaceRoot(cwd) {
6
- const workspaceImplementation = preferred || implementations_1.getWorkspaceImplementation(cwd);
7
+ const workspaceImplementation = preferred || (0, implementations_1.getWorkspaceImplementation)(cwd);
7
8
  if (!workspaceImplementation) {
8
9
  return;
9
10
  }
@@ -1,9 +1,10 @@
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
5
  const preferred = process.env.PREFERRED_WORKSPACE_MANAGER;
5
6
  function getWorkspaces(cwd) {
6
- const workspaceImplementation = preferred || implementations_1.getWorkspaceImplementation(cwd);
7
+ const workspaceImplementation = preferred || (0, implementations_1.getWorkspaceImplementation)(cwd);
7
8
  if (!workspaceImplementation) {
8
9
  return [];
9
10
  }
@@ -3,8 +3,12 @@ export interface ImplementationAndLockFile {
3
3
  implementation: WorkspaceImplementations | undefined;
4
4
  lockFile: string;
5
5
  }
6
- export declare function getWorkspaceImplementationAndLockFile(cwd: string): {
6
+ export declare function getWorkspaceImplementationAndLockFile(cwd: string, cache?: {
7
+ [cwd: string]: ImplementationAndLockFile;
8
+ }): {
7
9
  implementation: WorkspaceImplementations | undefined;
8
10
  lockFile: string;
9
11
  } | undefined;
10
- export declare function getWorkspaceImplementation(cwd: string): WorkspaceImplementations | undefined;
12
+ export declare function getWorkspaceImplementation(cwd: string, cache?: {
13
+ [cwd: string]: ImplementationAndLockFile;
14
+ }): WorkspaceImplementations | undefined;
@@ -3,14 +3,15 @@ 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
8
  const path_1 = __importDefault(require("path"));
8
- const cache = {};
9
- function getWorkspaceImplementationAndLockFile(cwd) {
9
+ const workspaceCache = {};
10
+ function getWorkspaceImplementationAndLockFile(cwd, cache = workspaceCache) {
10
11
  if (cache[cwd]) {
11
12
  return cache[cwd];
12
13
  }
13
- const lockFile = find_up_1.default.sync(["lerna.json", "yarn.lock", "pnpm-workspace.yaml", "rush.json", "package-lock.json"], {
14
+ const lockFile = find_up_1.default.sync(["lerna.json", "rush.json", "yarn.lock", "pnpm-workspace.yaml", "package-lock.json"], {
14
15
  cwd,
15
16
  });
16
17
  if (!lockFile) {
@@ -51,8 +52,8 @@ function getWorkspaceImplementationAndLockFile(cwd) {
51
52
  return cache[cwd];
52
53
  }
53
54
  exports.getWorkspaceImplementationAndLockFile = getWorkspaceImplementationAndLockFile;
54
- function getWorkspaceImplementation(cwd) {
55
+ function getWorkspaceImplementation(cwd, cache = workspaceCache) {
55
56
  var _a;
56
- return (_a = getWorkspaceImplementationAndLockFile(cwd)) === null || _a === void 0 ? void 0 : _a.implementation;
57
+ return (_a = getWorkspaceImplementationAndLockFile(cwd, cache)) === null || _a === void 0 ? void 0 : _a.implementation;
57
58
  }
58
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
  }
@@ -11,6 +12,6 @@ function getNpmWorkspaceRoot(cwd) {
11
12
  exports.getNpmWorkspaceRoot = getNpmWorkspaceRoot;
12
13
  function getNpmWorkspaces(cwd) {
13
14
  const npmWorkspacesRoot = getNpmWorkspaceRoot(cwd);
14
- return packageJsonWorkspaces_1.getWorkspaceInfoFromWorkspaceRoot(npmWorkspacesRoot);
15
+ return (0, packageJsonWorkspaces_1.getWorkspaceInfoFromWorkspaceRoot)(npmWorkspacesRoot);
15
16
  }
16
17
  exports.getNpmWorkspaces = getNpmWorkspaces;
@@ -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.getWorkspaceInfoFromWorkspaceRoot = exports.getPackageJsonWorkspaceRoot = void 0;
6
7
  const fs_1 = __importDefault(require("fs"));
7
8
  const path_1 = __importDefault(require("path"));
8
9
  const _1 = require(".");
@@ -10,7 +11,7 @@ const getPackagePaths_1 = require("../../getPackagePaths");
10
11
  const getWorkspacePackageInfo_1 = require("../getWorkspacePackageInfo");
11
12
  function getPackageJsonWorkspaceRoot(cwd) {
12
13
  var _a;
13
- const lockFile = (_a = _1.getWorkspaceImplementationAndLockFile(cwd)) === null || _a === void 0 ? void 0 : _a.lockFile;
14
+ const lockFile = (_a = (0, _1.getWorkspaceImplementationAndLockFile)(cwd)) === null || _a === void 0 ? void 0 : _a.lockFile;
14
15
  const packageJsonWorkspacesRoot = lockFile ? path_1.default.dirname(lockFile) : cwd;
15
16
  return packageJsonWorkspacesRoot;
16
17
  }
@@ -39,8 +40,8 @@ function getWorkspaceInfoFromWorkspaceRoot(packageJsonWorkspacesRoot) {
39
40
  try {
40
41
  const rootPackageJson = getRootPackageJson(packageJsonWorkspacesRoot);
41
42
  const packages = getPackages(rootPackageJson);
42
- const packagePaths = getPackagePaths_1.getPackagePaths(packageJsonWorkspacesRoot, packages);
43
- const workspaceInfo = getWorkspacePackageInfo_1.getWorkspacePackageInfo(packagePaths);
43
+ const packagePaths = (0, getPackagePaths_1.getPackagePaths)(packageJsonWorkspacesRoot, packages);
44
+ const workspaceInfo = (0, getWorkspacePackageInfo_1.getWorkspacePackageInfo)(packagePaths);
44
45
  return workspaceInfo;
45
46
  }
46
47
  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.getPnpmWorkspaces = exports.getPnpmWorkspaceRoot = void 0;
6
7
  const path_1 = __importDefault(require("path"));
7
8
  const find_up_1 = __importDefault(require("find-up"));
8
9
  const getPackagePaths_1 = require("../../getPackagePaths");
@@ -21,8 +22,8 @@ function getPnpmWorkspaces(cwd) {
21
22
  const pnpmWorkspacesFile = path_1.default.join(pnpmWorkspacesRoot, "pnpm-workspace.yaml");
22
23
  const readYaml = require("read-yaml-file").sync;
23
24
  const pnpmWorkspaces = readYaml(pnpmWorkspacesFile);
24
- const packagePaths = getPackagePaths_1.getPackagePaths(pnpmWorkspacesRoot, pnpmWorkspaces.packages);
25
- const workspaceInfo = getWorkspacePackageInfo_1.getWorkspacePackageInfo(packagePaths);
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.18.0",
3
+ "version": "0.18.3",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -38,6 +38,6 @@
38
38
  "jest": "^25.0.0",
39
39
  "tmp": "^0.2.1",
40
40
  "ts-jest": "^25.5.1",
41
- "typescript": "3.8.3"
41
+ "typescript": "^4.5.4"
42
42
  }
43
43
  }