git-er-done 0.1.16 → 0.1.17

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "git-er-done",
3
- "version": "0.1.16",
3
+ "version": "0.1.17",
4
4
  "description": "Utility for dealing with modified, created, deleted files since a git commit",
5
5
  "main": "src/index.js",
6
6
  "types": "types/index.d.ts",
@@ -1,19 +1,24 @@
1
1
  const { executeCommand } = require('./utils/exec')
2
2
 
3
- let gitRoot
3
+ /** @type {Map<string, string>} */
4
+ const gitRootCache = new Map()
5
+
4
6
  /**
5
7
  * Gets the root directory of the git repository
6
8
  * @returns {Promise<string>} A promise that resolves to the root directory path of the git repository
7
9
  */
8
10
  function getGitRoot() {
9
11
  return new Promise((resolve, reject) => {
10
- if (gitRoot) {
11
- return resolve(gitRoot)
12
+ const cwd = process.cwd()
13
+ const cached = gitRootCache.get(cwd)
14
+ if (cached) {
15
+ return resolve(cached)
12
16
  }
13
17
  executeCommand('git rev-parse --show-toplevel', (err, res) => {
14
18
  if (err) return reject(err)
15
- gitRoot = res.trim()
16
- resolve(res.trim())
19
+ const root = res.trim()
20
+ gitRootCache.set(cwd, root)
21
+ resolve(root)
17
22
  })
18
23
  })
19
24
  }