workspace-tools 0.21.0 → 0.23.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/CHANGELOG.json +54 -1
  2. package/CHANGELOG.md +30 -2
  3. package/lib/dependencies/index.d.ts +12 -0
  4. package/lib/dependencies/index.js +14 -0
  5. package/lib/{dependencies.d.ts → dependencies/transitiveDeps.d.ts} +1 -7
  6. package/lib/{dependencies.js → dependencies/transitiveDeps.js} +3 -12
  7. package/lib/{createDependencyMap.d.ts → graph/createDependencyMap.d.ts} +3 -5
  8. package/lib/{createDependencyMap.js → graph/createDependencyMap.js} +3 -2
  9. package/lib/graph/createPackageGraph.d.ts +10 -0
  10. package/lib/graph/createPackageGraph.js +122 -0
  11. package/lib/graph/getPackageDependencies.d.ts +6 -0
  12. package/lib/graph/getPackageDependencies.js +20 -0
  13. package/lib/graph/index.d.ts +3 -0
  14. package/lib/graph/index.js +16 -0
  15. package/lib/index.d.ts +2 -2
  16. package/lib/index.js +2 -2
  17. package/lib/lockfile/index.js +2 -2
  18. package/package.json +5 -3
  19. package/.github/workflows/pr.yml +0 -29
  20. package/.github/workflows/release.yml +0 -36
  21. package/.prettierrc +0 -6
  22. package/CODE_OF_CONDUCT.md +0 -9
  23. package/SECURITY.md +0 -41
  24. package/beachball.config.js +0 -12
  25. package/docs/.nojekyll +0 -1
  26. package/docs/assets/highlight.css +0 -22
  27. package/docs/assets/icons.css +0 -1043
  28. package/docs/assets/icons.png +0 -0
  29. package/docs/assets/icons@2x.png +0 -0
  30. package/docs/assets/main.js +0 -52
  31. package/docs/assets/search.js +0 -1
  32. package/docs/assets/style.css +0 -1414
  33. package/docs/assets/widgets.png +0 -0
  34. package/docs/assets/widgets@2x.png +0 -0
  35. package/docs/index.html +0 -42
  36. package/docs/interfaces/NpmLockFile.html +0 -1
  37. package/docs/interfaces/NpmSymlinkInfo.html +0 -1
  38. package/docs/interfaces/NpmWorkspacesInfo.html +0 -1
  39. package/docs/interfaces/PackageInfo.html +0 -1
  40. package/docs/interfaces/PackageInfos.html +0 -1
  41. package/docs/interfaces/PnpmLockFile.html +0 -1
  42. package/docs/modules.html +0 -70
  43. package/jest.config.js +0 -11
  44. package/lib/__tests__/dependencies.test.d.ts +0 -1
  45. package/lib/__tests__/dependencies.test.js +0 -141
  46. package/lib/__tests__/getChangedPackages.test.d.ts +0 -1
  47. package/lib/__tests__/getChangedPackages.test.js +0 -142
  48. package/lib/__tests__/getDefaultRemote.test.d.ts +0 -1
  49. package/lib/__tests__/getDefaultRemote.test.js +0 -26
  50. package/lib/__tests__/getInitDefaultBranch.test.d.ts +0 -1
  51. package/lib/__tests__/getInitDefaultBranch.test.js +0 -26
  52. package/lib/__tests__/getPackagesByFiles.test.d.ts +0 -1
  53. package/lib/__tests__/getPackagesByFiles.test.js +0 -54
  54. package/lib/__tests__/getScopedPackages.test.d.ts +0 -1
  55. package/lib/__tests__/getScopedPackages.test.js +0 -74
  56. package/lib/__tests__/getWorkspaceRoot.test.d.ts +0 -1
  57. package/lib/__tests__/getWorkspaceRoot.test.js +0 -40
  58. package/lib/__tests__/getWorkspaces.test.d.ts +0 -1
  59. package/lib/__tests__/getWorkspaces.test.js +0 -122
  60. package/lib/__tests__/graph.test.d.ts +0 -1
  61. package/lib/__tests__/graph.test.js +0 -117
  62. package/lib/__tests__/lockfile.test.d.ts +0 -1
  63. package/lib/__tests__/lockfile.test.js +0 -42
  64. package/lib/__tests__/queryLockFile.test.d.ts +0 -1
  65. package/lib/__tests__/queryLockFile.test.js +0 -43
  66. package/lib/graph.d.ts +0 -8
  67. package/lib/graph.js +0 -61
@@ -1,122 +0,0 @@
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
- const path_1 = __importDefault(require("path"));
7
- const setupFixture_1 = require("../helpers/setupFixture");
8
- const implementations_1 = require("../workspaces/implementations");
9
- const yarn_1 = require("../workspaces/implementations/yarn");
10
- const pnpm_1 = require("../workspaces/implementations/pnpm");
11
- const rush_1 = require("../workspaces/implementations/rush");
12
- const npm_1 = require("../workspaces/implementations/npm");
13
- const lerna_1 = require("../workspaces/implementations/lerna");
14
- describe("getWorkspaces", () => {
15
- afterAll(() => {
16
- (0, setupFixture_1.cleanupFixtures)();
17
- });
18
- describe("yarn", () => {
19
- it("gets the name and path of the workspaces", () => {
20
- const packageRoot = (0, setupFixture_1.setupFixture)("monorepo");
21
- expect((0, implementations_1.getWorkspaceImplementation)(packageRoot, {})).toBe("yarn");
22
- const workspacesPackageInfo = (0, yarn_1.getYarnWorkspaces)(packageRoot);
23
- const packageAPath = path_1.default.join(packageRoot, "packages", "package-a");
24
- const packageBPath = path_1.default.join(packageRoot, "packages", "package-b");
25
- expect(workspacesPackageInfo).toMatchObject([
26
- { name: "package-a", path: packageAPath },
27
- { name: "package-b", path: packageBPath },
28
- ]);
29
- });
30
- it("gets the name and path of the workspaces against a packages spec of an individual package", () => {
31
- const packageRoot = (0, setupFixture_1.setupFixture)("monorepo-globby");
32
- expect((0, implementations_1.getWorkspaceImplementation)(packageRoot, {})).toBe("yarn");
33
- const workspacesPackageInfo = (0, yarn_1.getYarnWorkspaces)(packageRoot);
34
- const packageAPath = path_1.default.join(packageRoot, "packages", "package-a");
35
- const packageBPath = path_1.default.join(packageRoot, "packages", "package-b");
36
- const individualPath = path_1.default.join(packageRoot, "packages", "individual");
37
- expect(workspacesPackageInfo).toMatchObject([
38
- { name: "individual", path: individualPath },
39
- { name: "package-a", path: packageAPath },
40
- { name: "package-b", path: packageBPath },
41
- ]);
42
- });
43
- });
44
- describe("pnpm", () => {
45
- it("gets the name and path of the workspaces", () => {
46
- const packageRoot = (0, setupFixture_1.setupFixture)("monorepo-pnpm");
47
- expect((0, implementations_1.getWorkspaceImplementation)(packageRoot, {})).toBe("pnpm");
48
- const workspacesPackageInfo = (0, pnpm_1.getPnpmWorkspaces)(packageRoot);
49
- const packageAPath = path_1.default.join(packageRoot, "packages", "package-a");
50
- const packageBPath = path_1.default.join(packageRoot, "packages", "package-b");
51
- expect(workspacesPackageInfo).toMatchObject([
52
- { name: "package-a", path: packageAPath },
53
- { name: "package-b", path: packageBPath },
54
- ]);
55
- });
56
- });
57
- describe("rush + pnpm", () => {
58
- it("gets the name and path of the workspaces", () => {
59
- const packageRoot = (0, setupFixture_1.setupFixture)("monorepo-rush-pnpm");
60
- expect((0, implementations_1.getWorkspaceImplementation)(packageRoot, {})).toBe("rush");
61
- const workspacesPackageInfo = (0, rush_1.getRushWorkspaces)(packageRoot);
62
- const packageAPath = path_1.default.join(packageRoot, "packages", "package-a");
63
- const packageBPath = path_1.default.join(packageRoot, "packages", "package-b");
64
- expect(workspacesPackageInfo).toMatchObject([
65
- { name: "package-a", path: packageAPath },
66
- { name: "package-b", path: packageBPath },
67
- ]);
68
- });
69
- });
70
- describe("rush + yarn", () => {
71
- it("gets the name and path of the workspaces", () => {
72
- const packageRoot = (0, setupFixture_1.setupFixture)("monorepo-rush-yarn");
73
- expect((0, implementations_1.getWorkspaceImplementation)(packageRoot, {})).toBe("rush");
74
- const workspacesPackageInfo = (0, rush_1.getRushWorkspaces)(packageRoot);
75
- const packageAPath = path_1.default.join(packageRoot, "packages", "package-a");
76
- const packageBPath = path_1.default.join(packageRoot, "packages", "package-b");
77
- expect(workspacesPackageInfo).toMatchObject([
78
- { name: "package-a", path: packageAPath },
79
- { name: "package-b", path: packageBPath },
80
- ]);
81
- });
82
- });
83
- describe("npm", () => {
84
- it("gets the name and path of the workspaces", () => {
85
- const packageRoot = (0, setupFixture_1.setupFixture)("monorepo-npm");
86
- expect((0, implementations_1.getWorkspaceImplementation)(packageRoot, {})).toBe("npm");
87
- const workspacesPackageInfo = (0, npm_1.getNpmWorkspaces)(packageRoot);
88
- const packageAPath = path_1.default.join(packageRoot, "packages", "package-a");
89
- const packageBPath = path_1.default.join(packageRoot, "packages", "package-b");
90
- expect(workspacesPackageInfo).toMatchObject([
91
- { name: "package-a", path: packageAPath },
92
- { name: "package-b", path: packageBPath },
93
- ]);
94
- });
95
- it("gets the name and path of the workspaces using the shorthand configuration", () => {
96
- const packageRoot = (0, setupFixture_1.setupFixture)("monorepo-shorthand");
97
- expect((0, implementations_1.getWorkspaceImplementation)(packageRoot, {})).toBe("npm");
98
- const workspacesPackageInfo = (0, npm_1.getNpmWorkspaces)(packageRoot);
99
- const packageAPath = path_1.default.join(packageRoot, "packages", "package-a");
100
- const packageBPath = path_1.default.join(packageRoot, "packages", "package-b");
101
- const individualPath = path_1.default.join(packageRoot, "individual");
102
- expect(workspacesPackageInfo).toMatchObject([
103
- { name: "package-a", path: packageAPath },
104
- { name: "package-b", path: packageBPath },
105
- { name: "individual", path: individualPath },
106
- ]);
107
- });
108
- });
109
- describe("lerna", () => {
110
- it("gets the name and path of the workspaces", async () => {
111
- const packageRoot = (0, setupFixture_1.setupFixture)("monorepo-lerna-npm");
112
- expect((0, implementations_1.getWorkspaceImplementation)(packageRoot, {})).toBe("lerna");
113
- const workspacesPackageInfo = (0, lerna_1.getLernaWorkspaces)(packageRoot);
114
- const packageAPath = path_1.default.join(packageRoot, "packages", "package-a");
115
- const packageBPath = path_1.default.join(packageRoot, "packages", "package-b");
116
- expect(workspacesPackageInfo).toMatchObject([
117
- { name: "package-a", path: packageAPath },
118
- { name: "package-b", path: packageBPath },
119
- ]);
120
- });
121
- });
122
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,117 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const graph_1 = require("../graph");
4
- describe("createPackageGraph", () => {
5
- it("can get linear dependencies", () => {
6
- const allPackages = {
7
- a: stubPackage("a", ["b"]),
8
- b: stubPackage("b", ["c"]),
9
- c: stubPackage("c"),
10
- };
11
- const actual = (0, graph_1.createPackageGraph)(allPackages, { namePatterns: ["a"], includeDependencies: true });
12
- expect(actual).toMatchInlineSnapshot(`
13
- Object {
14
- "dependencies": Array [
15
- Object {
16
- "dependency": "b",
17
- "name": "a",
18
- },
19
- Object {
20
- "dependency": "c",
21
- "name": "b",
22
- },
23
- ],
24
- "packages": Array [
25
- "a",
26
- "b",
27
- "c",
28
- ],
29
- }
30
- `);
31
- });
32
- it("can represent a graph with some nodes with no edges", () => {
33
- const allPackages = {
34
- a: stubPackage("a"),
35
- b: stubPackage("b"),
36
- c: stubPackage("c"),
37
- };
38
- const actual = (0, graph_1.createPackageGraph)(allPackages);
39
- expect(actual).toMatchInlineSnapshot(`
40
- Object {
41
- "dependencies": Array [],
42
- "packages": Array [
43
- "c",
44
- "b",
45
- "a",
46
- ],
47
- }
48
- `);
49
- });
50
- it("can get linear dependents", () => {
51
- const allPackages = {
52
- a: stubPackage("a", ["b"]),
53
- b: stubPackage("b", ["c"]),
54
- c: stubPackage("c"),
55
- };
56
- const actual = (0, graph_1.createPackageGraph)(allPackages, { namePatterns: ["c"], includeDependents: true });
57
- expect(actual).toMatchInlineSnapshot(`
58
- Object {
59
- "dependencies": Array [
60
- Object {
61
- "dependency": "c",
62
- "name": "b",
63
- },
64
- Object {
65
- "dependency": "b",
66
- "name": "a",
67
- },
68
- ],
69
- "packages": Array [
70
- "c",
71
- "b",
72
- "a",
73
- ],
74
- }
75
- `);
76
- });
77
- it("will handle circular dependencies", () => {
78
- const allPackages = {
79
- a: stubPackage("a", ["b"]),
80
- b: stubPackage("b", ["c"]),
81
- c: stubPackage("c", ["a"]),
82
- };
83
- const actual = (0, graph_1.createPackageGraph)(allPackages, { namePatterns: ["a"], includeDependencies: true });
84
- expect(actual).toMatchInlineSnapshot(`
85
- Object {
86
- "dependencies": Array [
87
- Object {
88
- "dependency": "b",
89
- "name": "a",
90
- },
91
- Object {
92
- "dependency": "c",
93
- "name": "b",
94
- },
95
- Object {
96
- "dependency": "a",
97
- "name": "c",
98
- },
99
- ],
100
- "packages": Array [
101
- "a",
102
- "b",
103
- "c",
104
- ],
105
- }
106
- `);
107
- });
108
- });
109
- function stubPackage(name, deps = []) {
110
- return {
111
- name,
112
- packageJsonPath: `packages/${name}`,
113
- version: "1.0",
114
- dependencies: deps.reduce((depMap, dep) => (Object.assign(Object.assign({}, depMap), { [dep]: "*" })), {}),
115
- devDependencies: {},
116
- };
117
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,42 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const setupFixture_1 = require("../helpers/setupFixture");
4
- const lockfile_1 = require("../lockfile");
5
- const ERROR_MESSAGES = {
6
- NO_LOCK: "You do not have yarn.lock, pnpm-lock.yaml or package-lock.json. Please use one of these package managers.",
7
- UNSUPPORTED: "Your package-lock.json version is not supported: lockfileVersion is 1. You need npm version 7 or above and package-lock version 2 or above. Please, upgrade npm or choose a different package manager.",
8
- };
9
- describe("parseLockFile()", () => {
10
- // General
11
- it("throws if it cannot find lock file", async () => {
12
- const packageRoot = await (0, setupFixture_1.setupFixture)("basic-without-lock-file");
13
- await expect((0, lockfile_1.parseLockFile)(packageRoot)).rejects.toThrow(ERROR_MESSAGES.NO_LOCK);
14
- });
15
- // NPM
16
- it("parses package-lock.json file when it is found", async () => {
17
- const packageRoot = await (0, setupFixture_1.setupFixture)("monorepo-npm");
18
- const parsedLockeFile = await (0, lockfile_1.parseLockFile)(packageRoot);
19
- expect(parsedLockeFile).toHaveProperty("type", "success");
20
- });
21
- it("throws if npm version is unsupported", async () => {
22
- const packageRoot = await (0, setupFixture_1.setupFixture)("monorepo-npm-unsupported");
23
- await expect((0, lockfile_1.parseLockFile)(packageRoot)).rejects.toThrow(ERROR_MESSAGES.UNSUPPORTED);
24
- });
25
- // Yarn
26
- it("parses yarn.lock file when it is found", async () => {
27
- const packageRoot = await (0, setupFixture_1.setupFixture)("basic");
28
- const parsedLockeFile = await (0, lockfile_1.parseLockFile)(packageRoot);
29
- expect(parsedLockeFile).toHaveProperty("type", "success");
30
- });
31
- it("parses combined ranges in yarn.lock", async () => {
32
- const packageRoot = await (0, setupFixture_1.setupFixture)("basic-yarn");
33
- const parsedLockeFile = await (0, lockfile_1.parseLockFile)(packageRoot);
34
- expect(parsedLockeFile.object["@babel/code-frame@^7.0.0"].version).toBe(parsedLockeFile.object["@babel/code-frame@^7.8.3"].version);
35
- });
36
- // PNPM
37
- it("parses pnpm-lock.yaml file when it is found", async () => {
38
- const packageRoot = await (0, setupFixture_1.setupFixture)("basic-pnpm");
39
- const parsedLockeFile = await (0, lockfile_1.parseLockFile)(packageRoot);
40
- expect(Object.keys(parsedLockeFile.object["yargs@16.2.0"].dependencies)).toContain("cliui");
41
- });
42
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const setupFixture_1 = require("../helpers/setupFixture");
4
- const __1 = require("..");
5
- /**
6
- * These tests rely on the "@microsoft/task-scheduler" package and its version as defined in package.json in
7
- * fixtures:
8
- * - monorepo-npm
9
- * - basic-yarn
10
- * - monorepo-pnpm
11
- *
12
- * If making any changes to those fixtures and "@microsoft/task-scheduler" dependency, update the `packageName` and
13
- * `packageVersion` constants.
14
- */
15
- const packageName = "@microsoft/task-scheduler";
16
- const packageVersion = "2.7.1";
17
- describe("queryLockFile()", () => {
18
- // NPM
19
- it("retrieves a dependency from a lock generated by npm", async () => {
20
- const packageRoot = await (0, setupFixture_1.setupFixture)("monorepo-npm");
21
- const parsedLockFile = await (0, __1.parseLockFile)(packageRoot);
22
- const result = (0, __1.queryLockFile)(packageName, packageVersion, parsedLockFile);
23
- expect(result).toBeDefined();
24
- expect(result.version).toBe(packageVersion);
25
- });
26
- // Yarn
27
- it("retrieves a dependency from a lock generated by yarn", async () => {
28
- const packageRoot = await (0, setupFixture_1.setupFixture)("basic-yarn");
29
- const parsedLockFile = await (0, __1.parseLockFile)(packageRoot);
30
- // NOTE: Yarn’s locks include ranges.
31
- const result = (0, __1.queryLockFile)(packageName, `^${packageVersion}`, parsedLockFile);
32
- expect(result).toBeDefined();
33
- expect(result.version).toBe(packageVersion);
34
- });
35
- // PNPM
36
- it("retrieves a dependency from a lock generated by pnpm", async () => {
37
- const packageRoot = await (0, setupFixture_1.setupFixture)("monorepo-pnpm");
38
- const parsedLockFile = await (0, __1.parseLockFile)(packageRoot);
39
- const result = (0, __1.queryLockFile)(packageName, packageVersion, parsedLockFile);
40
- expect(result).toBeDefined();
41
- expect(result.version).toBe(packageVersion);
42
- });
43
- });
package/lib/graph.d.ts DELETED
@@ -1,8 +0,0 @@
1
- import type { PackageInfos } from "./types/PackageInfo";
2
- import type { PackageGraph } from "./types/PackageGraph";
3
- export interface PackageGraphScope {
4
- namePatterns?: string[];
5
- includeDependencies?: boolean;
6
- includeDependents?: boolean;
7
- }
8
- export declare function createPackageGraph(packages: PackageInfos, scope?: PackageGraphScope): PackageGraph;
package/lib/graph.js DELETED
@@ -1,61 +0,0 @@
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.createPackageGraph = void 0;
7
- const createDependencyMap_1 = require("./createDependencyMap");
8
- const multimatch_1 = __importDefault(require("multimatch"));
9
- function createPackageGraph(packages, scope = {}) {
10
- const dependencyMap = (0, createDependencyMap_1.createDependencyMap)(packages);
11
- const packageSet = new Set();
12
- const edges = [];
13
- const visitor = (pkg, dependencies, dependents) => {
14
- packageSet.add(pkg);
15
- if (scope.includeDependencies && dependencies) {
16
- for (const dep of dependencies) {
17
- edges.push({ name: pkg, dependency: dep });
18
- packageSet.add(dep);
19
- }
20
- }
21
- if (scope.includeDependents && dependents) {
22
- for (const dep of dependents) {
23
- edges.push({ name: dep, dependency: pkg });
24
- packageSet.add(dep);
25
- }
26
- }
27
- };
28
- visitPackageGraph(packages, dependencyMap, visitor, scope);
29
- return { packages: [...packageSet], dependencies: edges };
30
- }
31
- exports.createPackageGraph = createPackageGraph;
32
- function visitPackageGraph(packages, dependencyMap, visitor, scope) {
33
- var _a, _b;
34
- const visited = new Set();
35
- const packageNames = Object.keys(packages);
36
- const stack = scope && scope.namePatterns ? (0, multimatch_1.default)(packageNames, scope.namePatterns) : packageNames;
37
- while (stack.length > 0) {
38
- const pkg = stack.pop();
39
- if (visited.has(pkg)) {
40
- continue;
41
- }
42
- const nextPkgs = [];
43
- let dependencies = [];
44
- let dependents = [];
45
- if (scope === null || scope === void 0 ? void 0 : scope.includeDependencies) {
46
- dependencies = [...(_a = dependencyMap.dependencies.get(pkg)) !== null && _a !== void 0 ? _a : []];
47
- nextPkgs.push(...dependencies);
48
- }
49
- if (scope === null || scope === void 0 ? void 0 : scope.includeDependents) {
50
- dependents = [...(_b = dependencyMap.dependents.get(pkg)) !== null && _b !== void 0 ? _b : []];
51
- nextPkgs.push(...dependents);
52
- }
53
- visitor(pkg, dependencies, dependents);
54
- visited.add(pkg);
55
- if (nextPkgs.length > 0) {
56
- for (const nextPkg of nextPkgs) {
57
- stack.push(nextPkg);
58
- }
59
- }
60
- }
61
- }