@psm14/semantic-release-path-filter 1.0.2 → 1.1.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/index.js +32 -6
- package/package.json +1 -1
package/index.js
CHANGED
@@ -1,21 +1,38 @@
|
|
1
1
|
import { execSync } from "child_process";
|
2
2
|
|
3
|
-
function filterCommits(commits, path) {
|
3
|
+
function filterCommits({ commits, logger }, path) {
|
4
4
|
return commits.filter((commit) => {
|
5
5
|
const changedFiles = getChangedFiles(commit.hash);
|
6
|
-
|
6
|
+
const isRelevant = changedFiles.some((file) => file.startsWith(path));
|
7
|
+
if (!isRelevant) {
|
8
|
+
logger.info(
|
9
|
+
`Filtered out commit ${commit.hash.slice(
|
10
|
+
0,
|
11
|
+
7
|
12
|
+
)} as it doesn't affect '${path}'`
|
13
|
+
);
|
14
|
+
}
|
15
|
+
return isRelevant;
|
7
16
|
});
|
8
17
|
}
|
9
18
|
|
19
|
+
const CHANGED_FILES_MEMO = new Map();
|
20
|
+
|
10
21
|
function getChangedFiles(commitHash) {
|
22
|
+
if (CHANGED_FILES_MEMO.has(commitHash)) {
|
23
|
+
return CHANGED_FILES_MEMO.get(commitHash);
|
24
|
+
}
|
25
|
+
|
11
26
|
try {
|
12
27
|
const result = execSync(
|
13
28
|
`git diff-tree --no-commit-id --name-only -r ${commitHash}`,
|
14
29
|
{ encoding: "utf-8" }
|
15
30
|
);
|
16
|
-
|
31
|
+
const changedFiles = result.trim().split("\n");
|
32
|
+
CHANGED_FILES_MEMO.set(commitHash, changedFiles);
|
33
|
+
return changedFiles;
|
17
34
|
} catch (error) {
|
18
|
-
|
35
|
+
logger.error(
|
19
36
|
`Error getting changed files for commit ${commitHash}:`,
|
20
37
|
error
|
21
38
|
);
|
@@ -37,13 +54,22 @@ function makePlugin(name) {
|
|
37
54
|
return;
|
38
55
|
}
|
39
56
|
|
57
|
+
const scopedLogger = context.logger.scope(
|
58
|
+
...context.logger.scopeName,
|
59
|
+
originalPluginName
|
60
|
+
);
|
40
61
|
const filteredContext =
|
41
62
|
"commits" in context
|
42
63
|
? {
|
43
64
|
...context,
|
44
|
-
commits: filterCommits(context
|
65
|
+
commits: filterCommits(context, path),
|
66
|
+
logger: scopedLogger,
|
45
67
|
}
|
46
|
-
:
|
68
|
+
: {
|
69
|
+
...context,
|
70
|
+
logger: scopedLogger,
|
71
|
+
};
|
72
|
+
|
47
73
|
return pluginModule[name](originalPluginConfig, filteredContext);
|
48
74
|
};
|
49
75
|
}
|