workspace-tools 0.18.2 → 0.19.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.
- package/CHANGELOG.json +46 -1
- package/CHANGELOG.md +26 -2
- package/lib/__tests__/getChangedPackages.test.js +17 -0
- package/lib/__tests__/getPackagesByFiles.test.d.ts +1 -0
- package/lib/__tests__/getPackagesByFiles.test.js +54 -0
- package/lib/__tests__/getWorkspaces.test.js +23 -2
- package/lib/git.js +4 -9
- package/lib/helpers/setupFixture.js +2 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/workspaces/getChangedPackages.d.ts +18 -0
- package/lib/workspaces/getChangedPackages.js +34 -27
- package/lib/workspaces/getPackagesByFiles.d.ts +10 -0
- package/lib/workspaces/getPackagesByFiles.js +38 -0
- package/lib/workspaces/implementations/index.d.ts +6 -2
- package/lib/workspaces/implementations/index.js +5 -5
- package/package.json +1 -1
package/CHANGELOG.json
CHANGED
|
@@ -2,7 +2,52 @@
|
|
|
2
2
|
"name": "workspace-tools",
|
|
3
3
|
"entries": [
|
|
4
4
|
{
|
|
5
|
-
"date": "
|
|
5
|
+
"date": "Thu, 05 May 2022 19:40:19 GMT",
|
|
6
|
+
"tag": "workspace-tools_v0.19.0",
|
|
7
|
+
"version": "0.19.0",
|
|
8
|
+
"comments": {
|
|
9
|
+
"minor": [
|
|
10
|
+
{
|
|
11
|
+
"author": "kchau@microsoft.com",
|
|
12
|
+
"package": "workspace-tools",
|
|
13
|
+
"comment": "adds a new API to allow retrieving a list of packages affected by files and also by git ref range",
|
|
14
|
+
"commit": "8d3b9dd8a8e1831b56a5f1606491be403debcbed"
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"date": "Wed, 20 Apr 2022 16:49:02 GMT",
|
|
21
|
+
"tag": "workspace-tools_v0.18.4",
|
|
22
|
+
"version": "0.18.4",
|
|
23
|
+
"comments": {
|
|
24
|
+
"patch": [
|
|
25
|
+
{
|
|
26
|
+
"author": "kchau@microsoft.com",
|
|
27
|
+
"package": "workspace-tools",
|
|
28
|
+
"comment": "fixes a potential security issue where fetch --upload-pack can allow for command injection",
|
|
29
|
+
"commit": "9bc7e65ce497f87e1f363fd47b8f802f3d3cd978"
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"date": "Sat, 09 Apr 2022 15:51:14 GMT",
|
|
36
|
+
"tag": "workspace-tools_v0.18.3",
|
|
37
|
+
"version": "0.18.3",
|
|
38
|
+
"comments": {
|
|
39
|
+
"patch": [
|
|
40
|
+
{
|
|
41
|
+
"author": "4123478+tido64@users.noreply.github.com",
|
|
42
|
+
"package": "workspace-tools",
|
|
43
|
+
"comment": "Fix Rush not being detected correctly. When Rush is set up to use Yarn or pnpm, the lock file for the latter are found first.",
|
|
44
|
+
"commit": "b99f6f82a6f22da37b67d74b519a204abd631c87"
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"date": "Fri, 07 Jan 2022 18:15:36 GMT",
|
|
6
51
|
"tag": "workspace-tools_v0.18.2",
|
|
7
52
|
"version": "0.18.2",
|
|
8
53
|
"comments": {
|
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,36 @@
|
|
|
1
1
|
# Change Log - workspace-tools
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Thu, 05 May 2022 19:40:19 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## 0.19.0
|
|
8
|
+
|
|
9
|
+
Thu, 05 May 2022 19:40:19 GMT
|
|
10
|
+
|
|
11
|
+
### Minor changes
|
|
12
|
+
|
|
13
|
+
- adds a new API to allow retrieving a list of packages affected by files and also by git ref range (kchau@microsoft.com)
|
|
14
|
+
|
|
15
|
+
## 0.18.4
|
|
16
|
+
|
|
17
|
+
Wed, 20 Apr 2022 16:49:02 GMT
|
|
18
|
+
|
|
19
|
+
### Patches
|
|
20
|
+
|
|
21
|
+
- fixes a potential security issue where fetch --upload-pack can allow for command injection (kchau@microsoft.com)
|
|
22
|
+
|
|
23
|
+
## 0.18.3
|
|
24
|
+
|
|
25
|
+
Sat, 09 Apr 2022 15:51:14 GMT
|
|
26
|
+
|
|
27
|
+
### Patches
|
|
28
|
+
|
|
29
|
+
- Fix Rush not being detected correctly. When Rush is set up to use Yarn or pnpm, the lock file for the latter are found first. (4123478+tido64@users.noreply.github.com)
|
|
30
|
+
|
|
7
31
|
## 0.18.2
|
|
8
32
|
|
|
9
|
-
Fri, 07 Jan 2022 18:15:
|
|
33
|
+
Fri, 07 Jan 2022 18:15:36 GMT
|
|
10
34
|
|
|
11
35
|
### Patches
|
|
12
36
|
|
|
@@ -122,4 +122,21 @@ describe("getChangedPackages()", () => {
|
|
|
122
122
|
// assert
|
|
123
123
|
expect(changedPkgs).toEqual([]);
|
|
124
124
|
});
|
|
125
|
+
it("can detect changed packages between two refs", () => {
|
|
126
|
+
// arrange
|
|
127
|
+
const root = (0, setupFixture_1.setupFixture)("monorepo");
|
|
128
|
+
const newFile = path_1.default.join(root, "packages/package-a/footest.txt");
|
|
129
|
+
fs_1.default.writeFileSync(newFile, "hello foo test");
|
|
130
|
+
(0, git_1.git)(["add", newFile], { cwd: root });
|
|
131
|
+
(0, git_1.stageAndCommit)(["packages/package-a/footest.txt"], "test commit in a", root);
|
|
132
|
+
const newFile2 = path_1.default.join(root, "packages/package-b/footest2.txt");
|
|
133
|
+
fs_1.default.writeFileSync(newFile2, "hello foo test");
|
|
134
|
+
(0, git_1.git)(["add", newFile2], { cwd: root });
|
|
135
|
+
(0, git_1.stageAndCommit)(["packages/package-b/footest2.txt"], "test commit in b", root);
|
|
136
|
+
// act
|
|
137
|
+
const changedPkgs = (0, getChangedPackages_1.getChangedPackagesBetweenRefs)(root, "HEAD^1", "HEAD");
|
|
138
|
+
// assert
|
|
139
|
+
expect(changedPkgs).toContain("package-b");
|
|
140
|
+
expect(changedPkgs).not.toContain("package-a");
|
|
141
|
+
});
|
|
125
142
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
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 fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const setupFixture_1 = require("../helpers/setupFixture");
|
|
9
|
+
const getPackagesByFiles_1 = require("../workspaces/getPackagesByFiles");
|
|
10
|
+
describe("getPackagesByFiles()", () => {
|
|
11
|
+
afterAll(() => {
|
|
12
|
+
(0, setupFixture_1.cleanupFixtures)();
|
|
13
|
+
});
|
|
14
|
+
it("can find all packages that contain the files in a monorepo", () => {
|
|
15
|
+
// arrange
|
|
16
|
+
const root = (0, setupFixture_1.setupFixture)("monorepo");
|
|
17
|
+
const newFile = path_1.default.join(root, "packages/package-a/footest.txt");
|
|
18
|
+
fs_1.default.writeFileSync(newFile, "hello foo test");
|
|
19
|
+
// act
|
|
20
|
+
const packages = (0, getPackagesByFiles_1.getPackagesByFiles)(root, ["packages/package-a/footest.txt"]);
|
|
21
|
+
// assert
|
|
22
|
+
expect(packages).toContain("package-a");
|
|
23
|
+
expect(packages).not.toContain("package-b");
|
|
24
|
+
});
|
|
25
|
+
it("can find can ignore changes in a glob pattern", () => {
|
|
26
|
+
// arrange
|
|
27
|
+
const root = (0, setupFixture_1.setupFixture)("monorepo");
|
|
28
|
+
const newFileA = path_1.default.join(root, "packages/package-a/footest.txt");
|
|
29
|
+
fs_1.default.writeFileSync(newFileA, "hello foo test");
|
|
30
|
+
const newFileB = path_1.default.join(root, "packages/package-b/footest.txt");
|
|
31
|
+
fs_1.default.writeFileSync(newFileB, "hello foo test");
|
|
32
|
+
// act
|
|
33
|
+
const packages = (0, getPackagesByFiles_1.getPackagesByFiles)(root, ["packages/package-a/footest.txt", "packages/package-b/footest.txt"], ["packages/package-b/**"]);
|
|
34
|
+
// assert
|
|
35
|
+
expect(packages).toContain("package-a");
|
|
36
|
+
expect(packages).not.toContain("package-b");
|
|
37
|
+
});
|
|
38
|
+
it("can find can handle empty files", () => {
|
|
39
|
+
// arrange
|
|
40
|
+
const root = (0, setupFixture_1.setupFixture)("monorepo");
|
|
41
|
+
// act
|
|
42
|
+
const packages = (0, getPackagesByFiles_1.getPackagesByFiles)(root, []);
|
|
43
|
+
// assert
|
|
44
|
+
expect(packages.length).toBe(0);
|
|
45
|
+
});
|
|
46
|
+
it("can find can handle unrelated files", () => {
|
|
47
|
+
// arrange
|
|
48
|
+
const root = (0, setupFixture_1.setupFixture)("monorepo");
|
|
49
|
+
// act
|
|
50
|
+
const packages = (0, getPackagesByFiles_1.getPackagesByFiles)(root, ["package.json"]);
|
|
51
|
+
// assert
|
|
52
|
+
expect(packages.length).toBe(0);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const path_1 = __importDefault(require("path"));
|
|
7
7
|
const setupFixture_1 = require("../helpers/setupFixture");
|
|
8
|
+
const implementations_1 = require("../workspaces/implementations");
|
|
8
9
|
const yarn_1 = require("../workspaces/implementations/yarn");
|
|
9
10
|
const pnpm_1 = require("../workspaces/implementations/pnpm");
|
|
10
11
|
const rush_1 = require("../workspaces/implementations/rush");
|
|
@@ -17,6 +18,7 @@ describe("getWorkspaces", () => {
|
|
|
17
18
|
describe("yarn", () => {
|
|
18
19
|
it("gets the name and path of the workspaces", () => {
|
|
19
20
|
const packageRoot = (0, setupFixture_1.setupFixture)("monorepo");
|
|
21
|
+
expect((0, implementations_1.getWorkspaceImplementation)(packageRoot, {})).toBe("yarn");
|
|
20
22
|
const workspacesPackageInfo = (0, yarn_1.getYarnWorkspaces)(packageRoot);
|
|
21
23
|
const packageAPath = path_1.default.join(packageRoot, "packages", "package-a");
|
|
22
24
|
const packageBPath = path_1.default.join(packageRoot, "packages", "package-b");
|
|
@@ -27,6 +29,7 @@ describe("getWorkspaces", () => {
|
|
|
27
29
|
});
|
|
28
30
|
it("gets the name and path of the workspaces against a packages spec of an individual package", () => {
|
|
29
31
|
const packageRoot = (0, setupFixture_1.setupFixture)("monorepo-globby");
|
|
32
|
+
expect((0, implementations_1.getWorkspaceImplementation)(packageRoot, {})).toBe("yarn");
|
|
30
33
|
const workspacesPackageInfo = (0, yarn_1.getYarnWorkspaces)(packageRoot);
|
|
31
34
|
const packageAPath = path_1.default.join(packageRoot, "packages", "package-a");
|
|
32
35
|
const packageBPath = path_1.default.join(packageRoot, "packages", "package-b");
|
|
@@ -41,6 +44,7 @@ describe("getWorkspaces", () => {
|
|
|
41
44
|
describe("pnpm", () => {
|
|
42
45
|
it("gets the name and path of the workspaces", () => {
|
|
43
46
|
const packageRoot = (0, setupFixture_1.setupFixture)("monorepo-pnpm");
|
|
47
|
+
expect((0, implementations_1.getWorkspaceImplementation)(packageRoot, {})).toBe("pnpm");
|
|
44
48
|
const workspacesPackageInfo = (0, pnpm_1.getPnpmWorkspaces)(packageRoot);
|
|
45
49
|
const packageAPath = path_1.default.join(packageRoot, "packages", "package-a");
|
|
46
50
|
const packageBPath = path_1.default.join(packageRoot, "packages", "package-b");
|
|
@@ -50,9 +54,23 @@ describe("getWorkspaces", () => {
|
|
|
50
54
|
]);
|
|
51
55
|
});
|
|
52
56
|
});
|
|
53
|
-
describe("rush", () => {
|
|
57
|
+
describe("rush + pnpm", () => {
|
|
54
58
|
it("gets the name and path of the workspaces", () => {
|
|
55
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");
|
|
56
74
|
const workspacesPackageInfo = (0, rush_1.getRushWorkspaces)(packageRoot);
|
|
57
75
|
const packageAPath = path_1.default.join(packageRoot, "packages", "package-a");
|
|
58
76
|
const packageBPath = path_1.default.join(packageRoot, "packages", "package-b");
|
|
@@ -65,6 +83,7 @@ describe("getWorkspaces", () => {
|
|
|
65
83
|
describe("npm", () => {
|
|
66
84
|
it("gets the name and path of the workspaces", () => {
|
|
67
85
|
const packageRoot = (0, setupFixture_1.setupFixture)("monorepo-npm");
|
|
86
|
+
expect((0, implementations_1.getWorkspaceImplementation)(packageRoot, {})).toBe("npm");
|
|
68
87
|
const workspacesPackageInfo = (0, npm_1.getNpmWorkspaces)(packageRoot);
|
|
69
88
|
const packageAPath = path_1.default.join(packageRoot, "packages", "package-a");
|
|
70
89
|
const packageBPath = path_1.default.join(packageRoot, "packages", "package-b");
|
|
@@ -75,6 +94,7 @@ describe("getWorkspaces", () => {
|
|
|
75
94
|
});
|
|
76
95
|
it("gets the name and path of the workspaces using the shorthand configuration", () => {
|
|
77
96
|
const packageRoot = (0, setupFixture_1.setupFixture)("monorepo-shorthand");
|
|
97
|
+
expect((0, implementations_1.getWorkspaceImplementation)(packageRoot, {})).toBe("npm");
|
|
78
98
|
const workspacesPackageInfo = (0, npm_1.getNpmWorkspaces)(packageRoot);
|
|
79
99
|
const packageAPath = path_1.default.join(packageRoot, "packages", "package-a");
|
|
80
100
|
const packageBPath = path_1.default.join(packageRoot, "packages", "package-b");
|
|
@@ -88,7 +108,8 @@ describe("getWorkspaces", () => {
|
|
|
88
108
|
});
|
|
89
109
|
describe("lerna", () => {
|
|
90
110
|
it("gets the name and path of the workspaces", async () => {
|
|
91
|
-
const packageRoot =
|
|
111
|
+
const packageRoot = (0, setupFixture_1.setupFixture)("monorepo-lerna-npm");
|
|
112
|
+
expect((0, implementations_1.getWorkspaceImplementation)(packageRoot, {})).toBe("lerna");
|
|
92
113
|
const workspacesPackageInfo = (0, lerna_1.getLernaWorkspaces)(packageRoot);
|
|
93
114
|
const packageAPath = path_1.default.join(packageRoot, "packages", "package-a");
|
|
94
115
|
const packageBPath = path_1.default.join(packageRoot, "packages", "package-b");
|
package/lib/git.js
CHANGED
|
@@ -104,14 +104,14 @@ function getUntrackedChanges(cwd) {
|
|
|
104
104
|
}
|
|
105
105
|
exports.getUntrackedChanges = getUntrackedChanges;
|
|
106
106
|
function fetchRemote(remote, cwd) {
|
|
107
|
-
const results = git(["fetch", remote], { cwd });
|
|
107
|
+
const results = git(["fetch", "--", remote], { cwd });
|
|
108
108
|
if (!results.success) {
|
|
109
109
|
throw gitError(`Cannot fetch remote: ${remote}`);
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
exports.fetchRemote = fetchRemote;
|
|
113
113
|
function fetchRemoteBranch(remote, remoteBranch, cwd) {
|
|
114
|
-
const results = git(["fetch", remote, remoteBranch], { cwd });
|
|
114
|
+
const results = git(["fetch", "--", remote, remoteBranch], { cwd });
|
|
115
115
|
if (!results.success) {
|
|
116
116
|
throw gitError(`Cannot fetch remote: ${remote} ${remoteBranch}`);
|
|
117
117
|
}
|
|
@@ -145,17 +145,12 @@ exports.getChanges = getChanges;
|
|
|
145
145
|
* @param cwd
|
|
146
146
|
*/
|
|
147
147
|
function getBranchChanges(branch, cwd) {
|
|
148
|
-
|
|
149
|
-
return processGitOutput(git(["--no-pager", "diff", "--name-only", "--relative", branch + "..."], { cwd }));
|
|
150
|
-
}
|
|
151
|
-
catch (e) {
|
|
152
|
-
throw gitError(`Cannot gather information about branch changes`, e);
|
|
153
|
-
}
|
|
148
|
+
return getChangesBetweenRefs(branch, "", [], "", cwd);
|
|
154
149
|
}
|
|
155
150
|
exports.getBranchChanges = getBranchChanges;
|
|
156
151
|
function getChangesBetweenRefs(fromRef, toRef, options, pattern, cwd) {
|
|
157
152
|
try {
|
|
158
|
-
return processGitOutput(git(["--no-pager", "diff", "--
|
|
153
|
+
return processGitOutput(git(["--no-pager", "diff", "--name-only", "--relative", ...options, `${fromRef}...${toRef}`, ...(pattern ? ["--", pattern] : [])], {
|
|
159
154
|
cwd,
|
|
160
155
|
}));
|
|
161
156
|
}
|
|
@@ -35,6 +35,8 @@ function setupFixture(fixtureName) {
|
|
|
35
35
|
fs_extra_1.default.mkdirpSync(cwd);
|
|
36
36
|
fs_extra_1.default.copySync(fixturePath, cwd);
|
|
37
37
|
(0, git_1.init)(cwd, "test@test.email", "test user");
|
|
38
|
+
// Ensure GPG signing doesn't interfere with tests
|
|
39
|
+
(0, git_1.gitFailFast)(["config", "commit.gpgsign", "false"], { cwd });
|
|
38
40
|
// Make the 'main' branch the default in the test repo
|
|
39
41
|
// ensure that the configuration for this repo does not collide
|
|
40
42
|
// with any global configuration the user had made, so we have
|
package/lib/index.d.ts
CHANGED
|
@@ -14,5 +14,6 @@ export * from "./workspaces/implementations/pnpm";
|
|
|
14
14
|
export * from "./workspaces/implementations/rush";
|
|
15
15
|
export * from "./workspaces/implementations/yarn";
|
|
16
16
|
export * from "./workspaces/getChangedPackages";
|
|
17
|
+
export * from "./workspaces/getPackagesByFiles";
|
|
17
18
|
export * from "./workspaces/listOfWorkspacePackageNames";
|
|
18
19
|
export * from "./workspaces/workspaces";
|
package/lib/index.js
CHANGED
|
@@ -26,5 +26,6 @@ __exportStar(require("./workspaces/implementations/pnpm"), exports);
|
|
|
26
26
|
__exportStar(require("./workspaces/implementations/rush"), exports);
|
|
27
27
|
__exportStar(require("./workspaces/implementations/yarn"), exports);
|
|
28
28
|
__exportStar(require("./workspaces/getChangedPackages"), exports);
|
|
29
|
+
__exportStar(require("./workspaces/getPackagesByFiles"), exports);
|
|
29
30
|
__exportStar(require("./workspaces/listOfWorkspacePackageNames"), exports);
|
|
30
31
|
__exportStar(require("./workspaces/workspaces"), exports);
|
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finds all packages that had been changed between two refs in the repo under cwd
|
|
3
|
+
*
|
|
4
|
+
* executes a "git diff $fromRef...$toRef" to get changes given a merge-base
|
|
5
|
+
*
|
|
6
|
+
* further explanation with the three dots:
|
|
7
|
+
*
|
|
8
|
+
* > git diff [--options] <commit>...<commit> [--] [<path>...]
|
|
9
|
+
* >
|
|
10
|
+
* > This form is to view the changes on the branch containing and up to
|
|
11
|
+
* > the second <commit>, starting at a common ancestor of both
|
|
12
|
+
* > <commit>. "git diff A...B" is equivalent to "git diff
|
|
13
|
+
* > $(git-merge-base A B) B". You can omit any one of <commit>, which
|
|
14
|
+
* > has the same effect as using HEAD instead.
|
|
15
|
+
*
|
|
16
|
+
* @returns string[] of package names that have changed
|
|
17
|
+
*/
|
|
18
|
+
export declare function getChangedPackagesBetweenRefs(cwd: string, fromRef: string, toRef?: string, ignoreGlobs?: string[]): string[];
|
|
1
19
|
/**
|
|
2
20
|
* Finds all packages that had been changed in the repo under cwd
|
|
3
21
|
*
|
|
@@ -1,13 +1,37 @@
|
|
|
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.getChangedPackages = void 0;
|
|
3
|
+
exports.getChangedPackages = exports.getChangedPackagesBetweenRefs = void 0;
|
|
7
4
|
const git_1 = require("../git");
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
const getPackagesByFiles_1 = require("./getPackagesByFiles");
|
|
6
|
+
/**
|
|
7
|
+
* Finds all packages that had been changed between two refs in the repo under cwd
|
|
8
|
+
*
|
|
9
|
+
* executes a "git diff $fromRef...$toRef" to get changes given a merge-base
|
|
10
|
+
*
|
|
11
|
+
* further explanation with the three dots:
|
|
12
|
+
*
|
|
13
|
+
* > git diff [--options] <commit>...<commit> [--] [<path>...]
|
|
14
|
+
* >
|
|
15
|
+
* > This form is to view the changes on the branch containing and up to
|
|
16
|
+
* > the second <commit>, starting at a common ancestor of both
|
|
17
|
+
* > <commit>. "git diff A...B" is equivalent to "git diff
|
|
18
|
+
* > $(git-merge-base A B) B". You can omit any one of <commit>, which
|
|
19
|
+
* > has the same effect as using HEAD instead.
|
|
20
|
+
*
|
|
21
|
+
* @returns string[] of package names that have changed
|
|
22
|
+
*/
|
|
23
|
+
function getChangedPackagesBetweenRefs(cwd, fromRef, toRef = "", ignoreGlobs = []) {
|
|
24
|
+
let changes = [
|
|
25
|
+
...new Set([
|
|
26
|
+
...((0, git_1.getUntrackedChanges)(cwd) || []),
|
|
27
|
+
...((0, git_1.getUnstagedChanges)(cwd) || []),
|
|
28
|
+
...((0, git_1.getChangesBetweenRefs)(fromRef, toRef, [], "", cwd) || []),
|
|
29
|
+
...((0, git_1.getStagedChanges)(cwd) || []),
|
|
30
|
+
]),
|
|
31
|
+
];
|
|
32
|
+
return (0, getPackagesByFiles_1.getPackagesByFiles)(cwd, changes, ignoreGlobs, true);
|
|
33
|
+
}
|
|
34
|
+
exports.getChangedPackagesBetweenRefs = getChangedPackagesBetweenRefs;
|
|
11
35
|
/**
|
|
12
36
|
* Finds all packages that had been changed in the repo under cwd
|
|
13
37
|
*
|
|
@@ -26,32 +50,15 @@ const path_1 = __importDefault(require("path"));
|
|
|
26
50
|
* @returns string[] of package names that have changed
|
|
27
51
|
*/
|
|
28
52
|
function getChangedPackages(cwd, target, ignoreGlobs = []) {
|
|
29
|
-
const
|
|
30
|
-
target = target || (0, git_1.getDefaultRemoteBranch)(undefined, cwd);
|
|
53
|
+
const targetBranch = target || (0, git_1.getDefaultRemoteBranch)(undefined, cwd);
|
|
31
54
|
let changes = [
|
|
32
55
|
...new Set([
|
|
33
56
|
...((0, git_1.getUntrackedChanges)(cwd) || []),
|
|
34
57
|
...((0, git_1.getUnstagedChanges)(cwd) || []),
|
|
35
|
-
...((0, git_1.getBranchChanges)(
|
|
58
|
+
...((0, git_1.getBranchChanges)(targetBranch, cwd) || []),
|
|
36
59
|
...((0, git_1.getStagedChanges)(cwd) || []),
|
|
37
60
|
]),
|
|
38
61
|
];
|
|
39
|
-
|
|
40
|
-
changes = changes.filter((change) => !ignoreSet.has(change));
|
|
41
|
-
const changeSet = new Set();
|
|
42
|
-
for (const change of changes) {
|
|
43
|
-
const candidates = workspaceInfo.filter((pkgPath) => change.indexOf(path_1.default.relative(cwd, pkgPath.path).replace(/\\/g, "/")) ===
|
|
44
|
-
0);
|
|
45
|
-
if (candidates && candidates.length > 0) {
|
|
46
|
-
const found = candidates.reduce((found, item) => {
|
|
47
|
-
return found.path.length > item.path.length ? found : item;
|
|
48
|
-
}, candidates[0]);
|
|
49
|
-
changeSet.add(found.name);
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
return workspaceInfo.map((pkg) => pkg.name);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return [...changeSet];
|
|
62
|
+
return (0, getPackagesByFiles_1.getPackagesByFiles)(cwd, changes, ignoreGlobs, true);
|
|
56
63
|
}
|
|
57
64
|
exports.getChangedPackages = getChangedPackages;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Given a list of files, finds all packages names that contain those files
|
|
3
|
+
*
|
|
4
|
+
* @param workspaceRoot - The root of the workspace
|
|
5
|
+
* @param files - files to search for
|
|
6
|
+
* @param ignoreGlobs - glob patterns to ignore
|
|
7
|
+
* @param returnAllPackagesOnNoMatch - if true, will return all packages if no matches are found
|
|
8
|
+
* @returns package names that have changed
|
|
9
|
+
*/
|
|
10
|
+
export declare function getPackagesByFiles(workspaceRoot: string, files: string[], ignoreGlobs?: string[], returnAllPackagesOnNoMatch?: boolean): string[];
|
|
@@ -0,0 +1,38 @@
|
|
|
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.getPackagesByFiles = void 0;
|
|
7
|
+
const multimatch_1 = __importDefault(require("multimatch"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const getWorkspaces_1 = require("./getWorkspaces");
|
|
10
|
+
/**
|
|
11
|
+
* Given a list of files, finds all packages names that contain those files
|
|
12
|
+
*
|
|
13
|
+
* @param workspaceRoot - The root of the workspace
|
|
14
|
+
* @param files - files to search for
|
|
15
|
+
* @param ignoreGlobs - glob patterns to ignore
|
|
16
|
+
* @param returnAllPackagesOnNoMatch - if true, will return all packages if no matches are found
|
|
17
|
+
* @returns package names that have changed
|
|
18
|
+
*/
|
|
19
|
+
function getPackagesByFiles(workspaceRoot, files, ignoreGlobs = [], returnAllPackagesOnNoMatch = false) {
|
|
20
|
+
const workspaceInfo = (0, getWorkspaces_1.getWorkspaces)(workspaceRoot);
|
|
21
|
+
const ignoreSet = new Set((0, multimatch_1.default)(files, ignoreGlobs));
|
|
22
|
+
files = files.filter((change) => !ignoreSet.has(change));
|
|
23
|
+
const packages = new Set();
|
|
24
|
+
for (const file of files) {
|
|
25
|
+
const candidates = workspaceInfo.filter((pkgPath) => file.indexOf(path_1.default.relative(workspaceRoot, pkgPath.path).replace(/\\/g, "/")) === 0);
|
|
26
|
+
if (candidates && candidates.length > 0) {
|
|
27
|
+
const found = candidates.reduce((found, item) => {
|
|
28
|
+
return found.path.length > item.path.length ? found : item;
|
|
29
|
+
}, candidates[0]);
|
|
30
|
+
packages.add(found.name);
|
|
31
|
+
}
|
|
32
|
+
else if (returnAllPackagesOnNoMatch) {
|
|
33
|
+
return workspaceInfo.map((pkg) => pkg.name);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return [...packages];
|
|
37
|
+
}
|
|
38
|
+
exports.getPackagesByFiles = getPackagesByFiles;
|
|
@@ -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
|
|
12
|
+
export declare function getWorkspaceImplementation(cwd: string, cache?: {
|
|
13
|
+
[cwd: string]: ImplementationAndLockFile;
|
|
14
|
+
}): WorkspaceImplementations | undefined;
|
|
@@ -6,12 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.getWorkspaceImplementation = exports.getWorkspaceImplementationAndLockFile = void 0;
|
|
7
7
|
const find_up_1 = __importDefault(require("find-up"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const
|
|
10
|
-
function getWorkspaceImplementationAndLockFile(cwd) {
|
|
9
|
+
const workspaceCache = {};
|
|
10
|
+
function getWorkspaceImplementationAndLockFile(cwd, cache = workspaceCache) {
|
|
11
11
|
if (cache[cwd]) {
|
|
12
12
|
return cache[cwd];
|
|
13
13
|
}
|
|
14
|
-
const lockFile = find_up_1.default.sync(["lerna.json", "yarn.lock", "pnpm-workspace.yaml", "
|
|
14
|
+
const lockFile = find_up_1.default.sync(["lerna.json", "rush.json", "yarn.lock", "pnpm-workspace.yaml", "package-lock.json"], {
|
|
15
15
|
cwd,
|
|
16
16
|
});
|
|
17
17
|
if (!lockFile) {
|
|
@@ -52,8 +52,8 @@ function getWorkspaceImplementationAndLockFile(cwd) {
|
|
|
52
52
|
return cache[cwd];
|
|
53
53
|
}
|
|
54
54
|
exports.getWorkspaceImplementationAndLockFile = getWorkspaceImplementationAndLockFile;
|
|
55
|
-
function getWorkspaceImplementation(cwd) {
|
|
55
|
+
function getWorkspaceImplementation(cwd, cache = workspaceCache) {
|
|
56
56
|
var _a;
|
|
57
|
-
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;
|
|
58
58
|
}
|
|
59
59
|
exports.getWorkspaceImplementation = getWorkspaceImplementation;
|