@psm14/semantic-release-path-filter 1.0.2 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/index.js +32 -6
  2. package/package.json +2 -2
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
- return changedFiles.some((file) => file.startsWith(path));
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
- return result.trim().split("\n");
31
+ const changedFiles = result.trim().split("\n");
32
+ CHANGED_FILES_MEMO.set(commitHash, changedFiles);
33
+ return changedFiles;
17
34
  } catch (error) {
18
- console.error(
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.commits, path),
65
+ commits: filterCommits(context, path),
66
+ logger: scopedLogger,
45
67
  }
46
- : context;
68
+ : {
69
+ ...context,
70
+ logger: scopedLogger,
71
+ };
72
+
47
73
  return pluginModule[name](originalPluginConfig, filteredContext);
48
74
  };
49
75
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@psm14/semantic-release-path-filter",
3
- "version": "1.0.2",
3
+ "version": "1.1.1",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -11,7 +11,7 @@
11
11
  "README.md"
12
12
  ],
13
13
  "author": "Patrick McLaughlin <me@patmclaughl.in>",
14
- "license": "ISC",
14
+ "license": "MIT",
15
15
  "description": "Wraps a semantic-release plugin to only run on commits in a specific path",
16
16
  "repository": {
17
17
  "type": "git",