monorepo-next 11.0.12 → 11.2.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/package.json +1 -1
- package/src/build-change-graph.js +29 -4
- package/src/git.js +19 -13
package/package.json
CHANGED
@@ -19,6 +19,14 @@ async function getPackageChangedFiles({
|
|
19
19
|
fromCommit,
|
20
20
|
toCommit,
|
21
21
|
packageCwd,
|
22
|
+
|
23
|
+
// I had a feeling it took more time to spawn git in a loop
|
24
|
+
// than the benefit you get by getting a git diff per-package,
|
25
|
+
// especially when you are using a `fromCommit` instead of version tags.
|
26
|
+
// In a test of mine, this brought `buildChangeGraph`
|
27
|
+
// down to 25 seconds from 39 seconds.
|
28
|
+
shouldRunPerPackage = true,
|
29
|
+
|
22
30
|
options,
|
23
31
|
}) {
|
24
32
|
// Be careful you don't accidentally use `...` instead of `..`.
|
@@ -27,11 +35,11 @@ async function getPackageChangedFiles({
|
|
27
35
|
//
|
28
36
|
// I tried using ls-tree instead of diff when it is a new package (fromCommit is first commit in repo),
|
29
37
|
// but it took the same amount of time.
|
30
|
-
let committedChanges = await git(['diff', '--name-only', `${fromCommit}..${toCommit}`, packageCwd], options);
|
38
|
+
let committedChanges = await git(['diff', '--name-only', `${fromCommit}..${toCommit}`, ...shouldRunPerPackage ? [packageCwd] : []], options);
|
31
39
|
|
32
40
|
committedChanges = getLinesFromOutput(committedChanges);
|
33
41
|
|
34
|
-
let dirtyChanges = await git(['status', '--porcelain', '--untracked-files', packageCwd], options);
|
42
|
+
let dirtyChanges = await git(['status', '--porcelain', '--untracked-files', ...shouldRunPerPackage ? [packageCwd] : []], options);
|
35
43
|
|
36
44
|
dirtyChanges = getLinesFromOutput(dirtyChanges).map(line => {
|
37
45
|
line = line.substr(3);
|
@@ -43,9 +51,25 @@ async function getPackageChangedFiles({
|
|
43
51
|
return line;
|
44
52
|
});
|
45
53
|
|
46
|
-
let changedFiles =
|
54
|
+
let changedFiles = new Set(committedChanges).union(dirtyChanges);
|
55
|
+
|
56
|
+
if (!shouldRunPerPackage) {
|
57
|
+
let packageChangedFiles = new Set();
|
58
|
+
|
59
|
+
let relativePackageCwd = path.relative(options.cwd, packageCwd);
|
60
|
+
|
61
|
+
for (let changedFile of changedFiles) {
|
62
|
+
if (!changedFile.startsWith(relativePackageCwd)) {
|
63
|
+
continue;
|
64
|
+
}
|
65
|
+
|
66
|
+
packageChangedFiles.add(changedFile);
|
67
|
+
}
|
68
|
+
|
69
|
+
changedFiles = packageChangedFiles;
|
70
|
+
}
|
47
71
|
|
48
|
-
return changedFiles;
|
72
|
+
return Array.from(changedFiles);
|
49
73
|
}
|
50
74
|
|
51
75
|
function crawlDag(dag, packagesWithChanges) {
|
@@ -136,6 +160,7 @@ async function buildChangeGraph({
|
|
136
160
|
fromCommit: _fromCommit,
|
137
161
|
toCommit,
|
138
162
|
packageCwd: _package.cwd,
|
163
|
+
shouldRunPerPackage: false,
|
139
164
|
options: {
|
140
165
|
cwd: workspaceMeta.cwd,
|
141
166
|
cached,
|
package/src/git.js
CHANGED
@@ -15,26 +15,32 @@ async function git(args, options) {
|
|
15
15
|
cached,
|
16
16
|
} = options;
|
17
17
|
|
18
|
-
let
|
18
|
+
let cacheKey;
|
19
19
|
|
20
|
-
|
20
|
+
if (cached) {
|
21
|
+
cacheKey = getCacheKey(args, cwd);
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
} else {
|
25
|
-
debug(args, options);
|
23
|
+
if (cacheKey in cache) {
|
24
|
+
debug('Git cache hit.');
|
26
25
|
|
27
|
-
|
28
|
-
cwd,
|
29
|
-
})).stdout;
|
30
|
-
|
31
|
-
if (cached) {
|
32
|
-
cache[cacheKey] = stdout;
|
26
|
+
return cache[cacheKey];
|
33
27
|
}
|
34
28
|
|
35
|
-
debug(
|
29
|
+
debug('Git cache miss.');
|
36
30
|
}
|
37
31
|
|
32
|
+
debug(args, options);
|
33
|
+
|
34
|
+
let stdout = (await execa('git', args, {
|
35
|
+
cwd,
|
36
|
+
})).stdout;
|
37
|
+
|
38
|
+
if (cached) {
|
39
|
+
cache[cacheKey] = stdout;
|
40
|
+
}
|
41
|
+
|
42
|
+
debug(stdout);
|
43
|
+
|
38
44
|
return stdout;
|
39
45
|
}
|
40
46
|
|